<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:import href="MiniEditorCommon.xslt"/>
  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="Variant" select="'!Any'"/>
  <xsl:param name="VersionRequestFrom">
    <xsl:value-of select="/MiniEditor/Pack//Requests_GZK_Realty/eDocument/@Version"/>
  </xsl:param>
  <xsl:param name="VersionMPFrom">
    <xsl:value-of select="/MiniEditor/Pack//STD_MP/eDocument/@Version"/>
  </xsl:param>
  <xsl:param name="VersionRequestTo">
    <xsl:value-of select="/MiniEditor/Forms/Form[@Code='Info']//Param[@Code='VersionRequest']"/>
  </xsl:param>
  <xsl:param name="VersionMPTo">
    <xsl:value-of select="/MiniEditor/Forms/Form[@Code='Info']//Param[@Code='VersionMP']"/>
  </xsl:param>
  <xsl:param name="SenderFrom">
    <xsl:value-of select="/MiniEditor/Pack//Forms/Form[@Code='Info']//ParamHidden[@Code='JF']"/>
  </xsl:param>
  <xsl:param name="SenderTo">
    <xsl:value-of select="/MiniEditor/Forms/Form[@Code='Info']//ParamHidden[@Code='JF']"/>
  </xsl:param>
  <xsl:param name="XMLDeclarant">
    <xsl:choose>
      <xsl:when test="count(/MiniEditor/Pack//Requests_GZK_Realty//Person)>0">F</xsl:when>
      <xsl:when test="count(/MiniEditor/Pack//Requests_GZK_Realty//Organization)>0">J</xsl:when>
    </xsl:choose>
  </xsl:param>
  <xsl:param name="MiniEditorExist">
    <xsl:choose>
      <xsl:when test="/MiniEditor/Pack/File/Content/MiniEditor">
        <xsl:text>true</xsl:text>
      </xsl:when>
      <xsl:otherwise>false</xsl:otherwise>
    </xsl:choose>
  </xsl:param>

  <!-- НЕ МЕНЯТЬ! -->

  <!-- Удаление @SetID -->
  <xsl:template match="@SetID"/>

  <!-- Удаление @SetDate в Forms (помечено mode="forms")-->
  <xsl:template match="@SetID" mode="forms"/>
  <xsl:template match="@SetDate" mode="forms"/>
  <xsl:template match="@*" mode="forms">
    <xsl:copy/>
  </xsl:template>

  <!-- Удаление @Selected и @ID и @ParentID в Form (помечено mode="form") -->
  <xsl:template match="@SetID" mode="form"/>
  <xsl:template match="@Selected" mode="form"/>
  <xsl:template match="@ID" mode="form"/>
  <xsl:template match="@ParentID" mode="form"/>
  <xsl:template match="@SetNumber" mode="form"/>

  <!-- Удаление @Selected и @SetNumber в Simple, Alt, Multi (помечено mode="part") -->
  <xsl:template match="@SetID" mode="part"/>
  <xsl:template match="@Selected" mode="part"/>
  <xsl:template match="@DefaultConditionTrue" mode="part"/>
  <xsl:template match="@*" mode="part">
    <xsl:copy/>
  </xsl:template>

  <!-- Удаление @Selected и @SetNumber в Section (помечено mode="section") -->
  <xsl:template match="@SetID" mode="section"/>
  <xsl:template match="@Selected" mode="section"/>
  <xsl:template match="@SetNumber" mode="section"/>
  <xsl:template match="@*" mode="section">
    <xsl:copy/>
  </xsl:template>

  <!-- Удаление @Selected в элементах Param параметра ParamSelect (помечено mode="param") -->
  <xsl:template match="@SetID" mode="param"/>
  <xsl:template match="@Selected" mode="param"/>
  <xsl:template match="@*" mode="param">
    <xsl:copy/>
  </xsl:template>

  <!-- Удаление @Selected в ParamSelect (помечено mode="paramselect") -->
  <xsl:template match="@SetID" mode="paramselect"/>
  <xsl:template match="@CodeSelected" mode="paramselect"/>
  <xsl:template match="@*" mode="paramselect">
    <xsl:copy/>
  </xsl:template>

  <!-- Главное преобразование (не надо менять) -->
  <xsl:template match="@* | node()">
    <xsl:choose>
      <!-- Удаление раздела Pack  -->
      <xsl:when test="local-name()='Pack'"/>
      <!-- Списки -->
      <xsl:when test="local-name()='Items'">
        <xsl:call-template name="Items">
          <xsl:with-param name="ListName" select="../@Name"/>
        </xsl:call-template>
      </xsl:when>
      <!-- Формы -->
      <xsl:when test="local-name()='MiniEditor'">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:when>
      <!-- Формы -->
      <xsl:when test="local-name()='Forms'">
        <xsl:call-template name="Forms"/>
      </xsl:when>
      <!-- Форма -->
      <xsl:when test="local-name()='Form'">
        <xsl:if test="@ParentID = ''">
          <xsl:call-template name="Form">
            <xsl:with-param name="PreviousFormPos" select="1"/>
          </xsl:call-template>
        </xsl:if>
      </xsl:when>
      <!-- Остальное -->
      <xsl:otherwise>
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Формы - копирование и рекурсивный вызов Form (не надо менять) -->
  <xsl:template name="FormCopy">
    <xsl:param name="ThisFormPos"/>
    <xsl:param name="ThisFormCode"/>
    <xsl:param name="ThisFormSelected"/>
    <xsl:param name="PreviousFormID"/>
    <xsl:param name="PreviousFormCode"/>
    <xsl:variable name="ThisFormID">
      <xsl:if test="$PreviousFormID!=''">
        <xsl:value-of select="$PreviousFormID"/>
        <xsl:text>.</xsl:text>
      </xsl:if>
      <xsl:value-of select="$ThisFormPos"/>
    </xsl:variable>
    <xsl:variable name="FormPos">
      <xsl:choose>
        <xsl:when test="not(contains($ThisFormID,'.'))">
          <xsl:value-of select="$ThisFormID"/>
        </xsl:when>
        <xsl:when
          test="contains($ThisFormID,'.') and not(contains(substring-after($ThisFormID,'.'),'.'))">
          <xsl:value-of select="substring-after($ThisFormID,'.')"/>
        </xsl:when>
        <xsl:when
          test="contains($ThisFormID,'.') and contains(substring-after($ThisFormID,'.'),'.')">
          <xsl:value-of select="substring-after(substring-after($ThisFormID,'.'),'.')"/>
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="FormPos1">
      <xsl:choose>
        <xsl:when test="not(contains($ThisFormID,'.'))">
          <xsl:value-of select="0"/>
        </xsl:when>
        <xsl:when
          test="contains($ThisFormID,'.') and not(contains(substring-after($ThisFormID,'.'),'.'))">
          <xsl:value-of select="substring-before($ThisFormID,'.')"/>
        </xsl:when>
        <xsl:when
          test="contains($ThisFormID,'.') and contains(substring-after($ThisFormID,'.'),'.')">
          <xsl:value-of select="substring-before(substring-after($ThisFormID,'.'),'.')"/>
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="FormPos2">
      <xsl:choose>
        <xsl:when test="not(contains($ThisFormID,'.'))">
          <xsl:value-of select="0"/>
        </xsl:when>
        <xsl:when
          test="contains($ThisFormID,'.') and not(contains(substring-after($ThisFormID,'.'),'.'))">
          <xsl:value-of select="0"/>
        </xsl:when>
        <xsl:when
          test="contains($ThisFormID,'.') and contains(substring-after($ThisFormID,'.'),'.')">
          <xsl:value-of select="substring-before(substring-before($ThisFormID,'.'),'.')"/>
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="FormCode">
      <xsl:value-of select="$ThisFormCode"/>
    </xsl:variable>
    <xsl:variable name="FormCode1">
      <xsl:value-of select="$PreviousFormCode"/>
    </xsl:variable>
    <!-- Копирование формы c заменой некоторых атрибутов -->
    <xsl:copy>
      <xsl:attribute name="Selected">
        <xsl:value-of select="$ThisFormSelected"/>
      </xsl:attribute>
      <xsl:attribute name="ID">
        <xsl:value-of select="$ThisFormID"/>
      </xsl:attribute>
      <xsl:attribute name="ParentID">
        <xsl:if test="$PreviousFormCode!=''">
          <xsl:value-of select="$PreviousFormCode"/>
          <xsl:text>_</xsl:text>
        </xsl:if>
        <xsl:value-of select="$PreviousFormID"/>
      </xsl:attribute>
      <xsl:attribute name="SetID">
        <xsl:value-of select="$ThisFormCode"/>
        <xsl:value-of select="$ThisFormID"/>
      </xsl:attribute>
      <xsl:if test="$ThisFormSelected='true' and @MaxOcc='*'">
        <xsl:attribute name="SetNumber">
          <xsl:value-of select="$ThisFormPos"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="@* | node()" mode="form">
        <xsl:with-param name="FormCode" select="$FormCode"/>
        <xsl:with-param name="FormCode1" select="$FormCode1"/>
        <xsl:with-param name="FormPos" select="$FormPos"/>
        <xsl:with-param name="FormPos1" select="$FormPos1"/>
        <xsl:with-param name="ThisFormSelected" select="$ThisFormSelected"/>
      </xsl:apply-templates>
    </xsl:copy>
    <!-- Рекурсивный вызов -->
    <xsl:for-each select="/MiniEditor/Forms/Form[substring-before(@ParentID,'_')=$ThisFormCode]">
      <xsl:call-template name="Form">
        <xsl:with-param name="PreviousFormID" select="$ThisFormID"/>
        <xsl:with-param name="PreviousFormCode" select="$ThisFormCode"/>
        <xsl:with-param name="PreviousFormPos" select="$ThisFormPos"/>
      </xsl:call-template>
    </xsl:for-each>
  </xsl:template>

  <!-- Преобразования внутри Form - cтраницы Page и разделы Simple, Alt, Multi - не надо менять -->
  <xsl:template match="@* | node()" mode="form">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="ThisFormSelected"/>
    <xsl:choose>
      <!-- Форма открыта (@Selected='true')-->
      <xsl:when test="$ThisFormSelected='true'">
        <!-- Копирование страницы с атрибутами -->
        <xsl:copy>
          <xsl:apply-templates select="@*"/>
          <xsl:for-each select="Simple | Alt | Multi">
            <xsl:variable name="PageCode" select="../@Code"/>
            <xsl:variable name="PartCode" select="@Code"/>
            <xsl:variable name="PartName" select="local-name()"/>
            <!--xsl:variable name="PartSelected" select="@Selected"/-->
            <xsl:variable name="ModalCode0">
              <xsl:if test="@Modal='Optional' or @Modal='ConditionalOptional'">
                <xsl:call-template name="ModalCode">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                </xsl:call-template>
              </xsl:if>
            </xsl:variable>
            <xsl:variable name="ModalCode">
              <xsl:choose>
                <xsl:when test="$ModalCode0='true' or $ModalCode0='false'">
                  <xsl:value-of select="$ModalCode0"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="@Selected"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <xsl:variable name="DefaultModalCode0">
              <xsl:if test="@Modal='ConditionalOptional'">
                <xsl:call-template name="DefaultModalCode">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                </xsl:call-template>
              </xsl:if>
            </xsl:variable>
            <xsl:variable name="DefaultModalCode">
              <xsl:choose>
                <xsl:when test="$DefaultModalCode0='true' or $DefaultModalCode0='false'">
                  <xsl:value-of select="$ModalCode"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="@DefaultConditionTrue"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:variable>
            <xsl:choose>
              <!-- Раздел открыт (Selected="true") -->
              <xsl:when test="$ModalCode='true'">
                <!-- Копирование открытого раздела -->
                <xsl:copy>
                  <xsl:apply-templates select="@*" mode="part"/>
                  <xsl:attribute name="Selected">
                    <xsl:value-of select="$ModalCode"/>
                  </xsl:attribute>
                  <xsl:if test="$DefaultModalCode='true' or $DefaultModalCode='false'">
                    <xsl:attribute name="DefaultConditionTrue">
                      <xsl:value-of select="$DefaultModalCode"/>
                    </xsl:attribute>
                  </xsl:if>
                  <!-- Раздел Simple -->
                  <xsl:if test="$PartName='Simple'">
                    <xsl:for-each select="Section">
                      <xsl:copy>
                        <xsl:apply-templates select="@*"/>
                        <xsl:for-each select="*">
                          <xsl:copy>
                            <xsl:call-template name="Param">
                              <xsl:with-param name="FormCode" select="$FormCode"/>
                              <xsl:with-param name="FormCode1" select="$FormCode1"/>
                              <xsl:with-param name="FormPos" select="$FormPos"/>
                              <xsl:with-param name="FormPos1" select="$FormPos1"/>
                              <xsl:with-param name="PageCode" select="$PageCode"/>
                              <xsl:with-param name="PartCode" select="$PartCode"/>
                              <xsl:with-param name="MultiPos" select="1"/>
                            </xsl:call-template>
                          </xsl:copy>
                        </xsl:for-each>
                      </xsl:copy>
                    </xsl:for-each>
                  </xsl:if>
                  <!-- Раздел Alt -->
                  <xsl:if test="$PartName='Alt'">
                    <xsl:variable name="AltCode">
                      <xsl:call-template name="AltCode">
                        <xsl:with-param name="FormCode" select="$FormCode"/>
                        <xsl:with-param name="FormCode1" select="$FormCode1"/>
                        <xsl:with-param name="FormPos" select="$FormPos"/>
                        <xsl:with-param name="FormPos1" select="$FormPos1"/>
                        <xsl:with-param name="PageCode" select="$PageCode"/>
                        <xsl:with-param name="PartCode" select="$PartCode"/>
                      </xsl:call-template>
                    </xsl:variable>
                    <xsl:variable name="AltCodeExist" select="Section[@Code=$AltCode]"/>
                    <xsl:for-each select="Section">
                      <xsl:variable name="AltSelected">
                        <xsl:choose>
                          <xsl:when test="$AltCodeExist">
                            <xsl:value-of select="@Code=$AltCode"/>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:value-of select="@Selected"/>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:variable>
                      <xsl:copy>
                        <xsl:attribute name="Selected">
                          <xsl:value-of select="$AltSelected"/>
                        </xsl:attribute>
                        <xsl:apply-templates select="@*" mode="section"/>
                        <xsl:choose>
                          <xsl:when test="$AltSelected='true'">
                            <xsl:for-each select="*">
                              <xsl:copy>
                                <xsl:call-template name="Param">
                                  <xsl:with-param name="FormCode" select="$FormCode"/>
                                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                                  <xsl:with-param name="FormPos" select="$FormPos"/>
                                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                                  <xsl:with-param name="PageCode" select="$PageCode"/>
                                  <xsl:with-param name="PartCode" select="$PartCode"/>
                                  <xsl:with-param name="AltCode" select="$AltCode"/>
                                  <xsl:with-param name="MultiPos" select="1"/>
                                </xsl:call-template>
                              </xsl:copy>
                            </xsl:for-each>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:apply-templates select="node()"/>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:copy>
                    </xsl:for-each>
                  </xsl:if>
                  <!-- Раздел Multi -->
                  <xsl:if test="$PartName='Multi'">
                    <xsl:call-template name="MultiPart">
                      <xsl:with-param name="FormCode" select="$FormCode"/>
                      <xsl:with-param name="FormCode1" select="$FormCode1"/>
                      <xsl:with-param name="FormPos" select="$FormPos"/>
                      <xsl:with-param name="FormPos1" select="$FormPos1"/>
                      <xsl:with-param name="PageCode" select="$PageCode"/>
                      <xsl:with-param name="PartCode" select="$PartCode"/>
                    </xsl:call-template>
                  </xsl:if>
                </xsl:copy>
              </xsl:when>
              <!-- Раздел закрыт (Selected="false") -->
              <xsl:otherwise>
                <!-- Копирование закрытого раздела -->
                <xsl:copy>
                  <xsl:apply-templates select="@*" mode="part"/>
                  <xsl:attribute name="Selected">
                    <xsl:value-of select="$ModalCode"/>
                  </xsl:attribute>
                  <xsl:apply-templates select="node()"/>
                </xsl:copy>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:for-each>
        </xsl:copy>
      </xsl:when>
      <!-- Форма закрыта (@Selected='false')-->
      <xsl:otherwise>
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Списки Lists: разделители для формирования строк ListOld и ListNew -->
  <xsl:variable name="ListSeparator">
    <xsl:text>{|}</xsl:text>
  </xsl:variable>
  <xsl:variable name="ListSeparator1">
    <xsl:text>{||}</xsl:text>
  </xsl:variable>
  <xsl:variable name="ListSeparator2">
    <xsl:text>{|@|}</xsl:text>
  </xsl:variable>

  <!-- Списки Lists: сохранение существующих Item в виде строки ListOld  (не надо менять) -->
  <!-- 
  Формат ListOld и ListNew:
  <ListSeparator><ThisListItem><ListId><ListSeparator>...<ListSeparator><ThisListItem><ListId><ListSeparator>
  Формат <ThisListItem>:
  <ListName><ListSeparator1><ListSeparator2><Значение><ListSeparator2>...<ListSeparator2><Значение><ListSeparator2><ListSeparator1>
  -->
  <xsl:variable name="ListOld">
    <xsl:for-each select="/MiniEditor/Lists/List">
      <xsl:variable name="ListName" select="@Name"/>
      <xsl:for-each select="Items/Item">
        <xsl:variable name="ListId" select="@id"/>
        <xsl:value-of select="$ListSeparator"/>
        <xsl:value-of select="$ListName"/>
        <xsl:value-of select="$ListSeparator1"/>
        <xsl:value-of select="$ListSeparator2"/>
        <xsl:for-each select="*">
          <xsl:value-of select="."/>
          <xsl:value-of select="$ListSeparator2"/>
        </xsl:for-each>
        <xsl:value-of select="$ListSeparator1"/>
        <xsl:value-of select="$ListId"/>
      </xsl:for-each>
    </xsl:for-each>
    <xsl:value-of select="$ListSeparator"/>
  </xsl:variable>

  <!-- Списки Lists: сохранение одного <ThisListItem> -->
  <!-- 
  Подходит для случая, когда в Pack все значения списка - элементы внутри одного элемента.
  Например, Params/Param 
  Надо менять, если в Pack есть списки, устроенные сложнее.
  -->
  <xsl:template name="ThisListItem">
    <xsl:param name="ListName"/>
    <xsl:value-of select="$ListSeparator"/>
    <xsl:value-of select="$ListName"/>
    <xsl:value-of select="$ListSeparator1"/>
    <xsl:value-of select="$ListSeparator2"/>
    <xsl:choose>
      <!-- Вариант Any -->
      <xsl:when test="$Variant='Any'">
        <xsl:for-each select="*">
          <xsl:value-of select="."/>
          <xsl:value-of select="$ListSeparator2"/>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <xsl:for-each select="*">
          <xsl:value-of select="."/>
          <xsl:value-of select="$ListSeparator2"/>
        </xsl:for-each>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="$ListSeparator1"/>
  </xsl:template>

  <!-- Раздел Multi, одна секция (не надо менять) -->
  <xsl:template name="MultiSection">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <xsl:param name="MultiPos"/>
    <xsl:for-each
      select="/MiniEditor/Forms/Form[@Code=$FormCode]/Page[@Code=$PageCode]/Multi[@Code=$PartCode]/Section[1]">
      <xsl:copy>
        <xsl:attribute name="SetNumber">
          <xsl:value-of select="$MultiPos"/>
        </xsl:attribute>
        <xsl:apply-templates select="@*" mode="section"/>
        <xsl:for-each select="*">
          <xsl:copy>
            <xsl:call-template name="Param">
              <xsl:with-param name="FormCode" select="$FormCode"/>
              <xsl:with-param name="FormCode1" select="$FormCode1"/>
              <xsl:with-param name="FormPos" select="$FormPos"/>
              <xsl:with-param name="FormPos1" select="$FormPos1"/>
              <xsl:with-param name="PageCode" select="$PageCode"/>
              <xsl:with-param name="PartCode" select="$PartCode"/>
              <xsl:with-param name="MultiPos" select="$MultiPos"/>
            </xsl:call-template>
          </xsl:copy>
        </xsl:for-each>
      </xsl:copy>
    </xsl:for-each>
  </xsl:template>

  <!-- Раздел Multi, одна секция: особый случай "точки"  -->
  <xsl:template name="MultiSectionPoint">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <xsl:param name="ContourPos"/>
    <xsl:param name="Spatial_ElementPos"/>
    <xsl:variable name="ContourAdd">
      <xsl:variable name="ContourPos1">
        <xsl:choose>
          <xsl:when test="$ContourPos=0">1</xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$ContourPos"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="ContourAdd1">
        <xsl:value-of select="$ContourPos1"/>
        <xsl:if test="$Spatial_ElementPos>1">
          <xsl:text>.</xsl:text>
          <xsl:value-of select="$Spatial_ElementPos - 1"/>
        </xsl:if>
      </xsl:variable>
      <xsl:if test="$ContourAdd1!=1 or count(../Spatial_Element)>1">
        <xsl:text> (</xsl:text>
        <xsl:value-of select="$ContourAdd1"/>
        <xsl:text>)</xsl:text>
      </xsl:if>
    </xsl:variable>
    <xsl:for-each select="Spelement_Unit">
      <xsl:variable name="UnitPos" select="position()"/>
      <xsl:for-each
        select="/MiniEditor/Forms/Form[@Code=$FormCode]/Page[@Code=$PageCode]/Multi[@Code=$PartCode]/Section[1]">
        <xsl:copy>
          <xsl:attribute name="SetNumber">
            <xsl:value-of select="$ContourPos"/>
            <xsl:text>.</xsl:text>
            <xsl:value-of select="$Spatial_ElementPos"/>
            <xsl:text>.</xsl:text>
            <xsl:value-of select="$UnitPos"/>
          </xsl:attribute>
          <xsl:apply-templates select="@*" mode="section"/>
          <xsl:for-each select="*">
            <xsl:copy>
              <xsl:call-template name="Param">
                <xsl:with-param name="FormCode" select="$FormCode"/>
                <xsl:with-param name="FormCode1" select="$FormCode1"/>
                <xsl:with-param name="FormPos" select="$FormPos"/>
                <xsl:with-param name="FormPos1" select="$FormPos1"/>
                <xsl:with-param name="PageCode" select="$PageCode"/>
                <xsl:with-param name="PartCode" select="$PartCode"/>
                <xsl:with-param name="ContourPos" select="$ContourPos"/>
                <xsl:with-param name="Spatial_ElementPos" select="$Spatial_ElementPos"/>
                <xsl:with-param name="UnitPos" select="$UnitPos"/>
                <xsl:with-param name="ContourAdd" select="$ContourAdd"/>
              </xsl:call-template>
            </xsl:copy>
          </xsl:for-each>
        </xsl:copy>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>

  <!-- Раздел Multi, одна секция: особый случай "ребра"  -->
  <xsl:template name="MultiSectionEdge">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <xsl:param name="ContourPos"/>
    <xsl:for-each select="Borders/Border">
      <xsl:variable name="UnitPos" select="position()"/>
      <xsl:variable name="ContourAdd">
        <xsl:variable name="ContourPos1">
          <xsl:choose>
            <xsl:when test="$ContourPos=0">1</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$ContourPos"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:variable name="ContourAdd1">
          <xsl:value-of select="$ContourPos1"/>
          <xsl:if test="@Spatial>1">
            <xsl:text>.</xsl:text>
            <xsl:value-of select="@Spatial - 1"/>
          </xsl:if>
        </xsl:variable>
        <xsl:if test="$ContourAdd1!=1 or count(../../Spatial_Element)>1">
          <xsl:text> (</xsl:text>
          <xsl:value-of select="$ContourAdd1"/>
          <xsl:text>)</xsl:text>
        </xsl:if>
      </xsl:variable>
      <xsl:for-each
        select="/MiniEditor/Forms/Form[@Code=$FormCode]/Page[@Code=$PageCode]/Multi[@Code=$PartCode]/Section[1]">
        <xsl:copy>
          <xsl:attribute name="SetNumber">
            <xsl:value-of select="$ContourPos"/>
            <xsl:text>.</xsl:text>
            <xsl:value-of select="$UnitPos"/>
          </xsl:attribute>
          <xsl:apply-templates select="@*" mode="section"/>
          <xsl:for-each select="*">
            <xsl:copy>
              <xsl:call-template name="Param">
                <xsl:with-param name="FormCode" select="$FormCode"/>
                <xsl:with-param name="FormCode1" select="$FormCode1"/>
                <xsl:with-param name="FormPos" select="$FormPos"/>
                <xsl:with-param name="FormPos1" select="$FormPos1"/>
                <xsl:with-param name="PageCode" select="$PageCode"/>
                <xsl:with-param name="PartCode" select="$PartCode"/>
                <xsl:with-param name="ContourPos" select="$ContourPos"/>
                <xsl:with-param name="UnitPos" select="$UnitPos"/>
                <xsl:with-param name="ContourAdd" select="$ContourAdd"/>
              </xsl:call-template>
            </xsl:copy>
          </xsl:for-each>
        </xsl:copy>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>

  <!-- Параметры (не надо менять) -->
  <xsl:template name="Param">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <xsl:param name="AltCode"/>
    <xsl:param name="MultiPos"/>
    <xsl:param name="ContourPos"/>
    <xsl:param name="Spatial_ElementPos"/>
    <xsl:param name="UnitPos"/>
    <xsl:param name="ContourAdd"/>
    <xsl:variable name="ParamCode" select="@Code"/>
    <xsl:choose>
      <!-- Параметр ParamSelect -->
      <xsl:when test="local-name()='ParamSelect'">
        <xsl:apply-templates select="@*" mode="paramselect"/>
        <xsl:variable name="ParamSelectCode">
          <xsl:call-template name="ParamValue">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="ParamCode" select="$ParamCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="AltCode" select="$AltCode"/>
            <xsl:with-param name="MultiPos" select="$MultiPos"/>
            <xsl:with-param name="ContourPos" select="$ContourPos"/>
            <xsl:with-param name="Spatial_ElementPos" select="$Spatial_ElementPos"/>
            <xsl:with-param name="UnitPos" select="$UnitPos"/>
            <xsl:with-param name="ContourAdd" select="$ContourAdd"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="ParamSelectCodeExist">
          <xsl:choose>
            <xsl:when test="Param/@Code=$ParamSelectCode">true</xsl:when>
            <xsl:otherwise>false</xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:if test="@CodeSelected">
          <xsl:attribute name="CodeSelected">
            <xsl:choose>
              <xsl:when test="$ParamSelectCodeExist='true'">
                <xsl:value-of select="$ParamSelectCode"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="@CodeSelected"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
        </xsl:if>
        <xsl:for-each select="Param">
          <xsl:copy>
            <xsl:apply-templates select="@*" mode="param"/>
            <xsl:attribute name="Selected">
              <xsl:choose>
                <xsl:when test="$ParamSelectCodeExist='true'">
                  <xsl:value-of select="@Code=$ParamSelectCode"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="@Selected"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:attribute>
          </xsl:copy>
        </xsl:for-each>
      </xsl:when>
      <!-- Параметр ParamSelectList -->
      <xsl:when test="local-name()='ParamSelectList'">
        <xsl:variable name="ListName" select="@ListName"/>
        <xsl:apply-templates select="@*"/>
        <xsl:variable name="ParamSelectListId">
          <xsl:call-template name="ParamSelectListId">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="AltCode" select="$AltCode"/>
            <xsl:with-param name="MultiPos" select="$MultiPos"/>
            <xsl:with-param name="ParamCode" select="$ParamCode"/>
            <xsl:with-param name="ListName" select="$ListName"/>
          </xsl:call-template>
        </xsl:variable>
        <Item>
          <xsl:attribute name="id">
            <xsl:value-of select="$ParamSelectListId"/>
          </xsl:attribute>
        </Item>
      </xsl:when>
      <!-- Параметры ParamHidden и ParamText - не надо менять -->
      <xsl:when test="local-name()='ParamHidden' or local-name()='ParamText'">
        <xsl:apply-templates select="@* | node()"/>
      </xsl:when>
      <!-- Другие параметры -->
      <xsl:otherwise>
        <xsl:apply-templates select="@*"/>
        <xsl:call-template name="ParamValue">
          <xsl:with-param name="FormCode" select="$FormCode"/>
          <xsl:with-param name="FormCode1" select="$FormCode1"/>
          <xsl:with-param name="FormPos" select="$FormPos"/>
          <xsl:with-param name="FormPos1" select="$FormPos1"/>
          <xsl:with-param name="PageCode" select="$PageCode"/>
          <xsl:with-param name="ParamCode" select="$ParamCode"/>
          <xsl:with-param name="PartCode" select="$PartCode"/>
          <xsl:with-param name="AltCode" select="$AltCode"/>
          <xsl:with-param name="MultiPos" select="$MultiPos"/>
          <xsl:with-param name="ContourPos" select="$ContourPos"/>
          <xsl:with-param name="Spatial_ElementPos" select="$Spatial_ElementPos"/>
          <xsl:with-param name="UnitPos" select="$UnitPos"/>
          <xsl:with-param name="ContourAdd" select="$ContourAdd"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Преобразование словарей между разными версиями схем -->
  <xsl:template name="while">
    <xsl:param name="code"/>
    <!-- передаваемый код в формате '|номер версии|код'  -->
    <xsl:param name="string"/>
    <!-- строка по которой осуществляется проход по блокам. В каждом цикле сдвиг на 1 блок -->
    <xsl:variable name="newstr">
      <!-- выделяем строку после начального кода словаря -->
      <xsl:value-of select="substring-after($string,'*')"/>
    </xsl:variable>
    <xsl:variable name="strbeforecode">
      <!-- после этого выделяем из строки newstr, идущую до переданного кода -->
      <xsl:value-of select="substring-before($newstr,$code)"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="substring-before($strbeforecode,'*')!=''">
        <!-- если строка strbeforecode имеет один или несколько блоков, содержащих *, то осуществляем сдвиг к следующему блоку -->
        <xsl:call-template name="while">
          <xsl:with-param name="code" select="$code"/>
          <xsl:with-param name="string" select="$newstr"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="substring-before($newstr,'#')"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="Trans">
    <xsl:param name="x"/>
    <!-- код для преобразования -->
    <xsl:param name="dict"/>
    <!-- название шаблона словаря -->
    <xsl:param name="in"/>
    <!-- исходная версия схемы -->
    <xsl:param name="out"/>
    <!-- желаемая версия схемы -->
    <!-- выделение нужного нам модуля -->
    <xsl:choose>
      <xsl:when test="$in=$out">
        <xsl:value-of select="$x"/>
      </xsl:when>
      <xsl:when
        test="$dict!='' and $x!='' and (substring-after($dict,$x)!='' or substring-before($dict,$x)!='')">
        <xsl:variable name="codein">
          <!-- код в формате '|номер регламента|код'  -->
          <xsl:text>|</xsl:text>
          <xsl:value-of select="$in"/>
          <xsl:text>|</xsl:text>
          <xsl:value-of select="$x"/>
        </xsl:variable>
        <xsl:variable name="codeout">
          <xsl:text>|</xsl:text>
          <xsl:value-of select="$out"/>
          <xsl:text>|</xsl:text>
        </xsl:variable>
        <xsl:variable name="block">
          <!-- поиск блока данных содержащий переданный код -->
          <xsl:call-template name="while">
            <xsl:with-param name="code" select="$codein"/>
            <!-- передаваемый код в формате '|номер версии|код'  -->
            <xsl:with-param name="string" select="$dict"/>
            <!-- исходная строка словаря -->
          </xsl:call-template>
        </xsl:variable>
        <xsl:choose>
          <xsl:when test="substring-before(substring-after($block,$codeout),'|')='-'">
            <xsl:value-of select="$x"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="substring-before(substring-after($block,$codeout),'|')"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- НИЖЕ - МЕНЯТЬ! НИЖЕ - МЕНЯТЬ! НИЖЕ - МЕНЯТЬ! НИЖЕ - МЕНЯТЬ! НИЖЕ - МЕНЯТЬ! НИЖЕ - МЕНЯТЬ! -->

  <!-- Формы: замена SetID и SetDate (надо менять) -->
  <xsl:template name="Forms">
    <xsl:copy>
      <xsl:choose>
        <!-- Вариант Any -->
        <xsl:when test="$Variant='Any'">
          <xsl:attribute name="SetID">
            <xsl:value-of
              select="substring-after(substring-before(//Pack/File/@FileName,'.xml'),'Any_')"/>
          </xsl:attribute>
          <xsl:attribute name="SetDate">
            <xsl:value-of select="//Pack//Forms/Date"/>
          </xsl:attribute>
          <xsl:apply-templates select="@*" mode="forms"/>
          <xsl:apply-templates select="node()"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:copy>
  </xsl:template>

  <!-- Формы: (надо менять) -->
  <xsl:template name="Form">
    <xsl:param name="PreviousFormID"/>
    <xsl:param name="PreviousFormCode"/>
    <xsl:param name="PreviousFormPos"/>
    <xsl:variable name="ThisFormCode" select="@Code"/>
    <xsl:if test="@Selected='false'">
      <xsl:call-template name="FormCopy">
        <xsl:with-param name="ThisFormPos" select="0"/>
        <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
        <xsl:with-param name="ThisFormSelected" select="'false'"/>
        <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
        <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
      </xsl:call-template>
    </xsl:if>
    <!-- Конкретный набор форм -->
    <xsl:choose>
      <!-- Вариант Any -->
      <xsl:when test="$Variant='Any'">
        <xsl:for-each
          select="/MiniEditor/Pack//*[local-name()='Forms' or (local-name()='Form' and @Code=$PreviousFormCode)][position()=$PreviousFormPos]/Form[@Code=$ThisFormCode]">
          <xsl:variable name="ThisPackPos" select="position()"/>
          <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
            <xsl:call-template name="FormCopy">
              <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
              <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
              <xsl:with-param name="ThisFormSelected" select="'true'"/>
              <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
              <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
            </xsl:call-template>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:when>
      <!-- Вариант MiniEditorExist -->
      <xsl:when test="$MiniEditorExist='true'">
        <xsl:variable name="MiniEditorExistParentID">
          <xsl:choose>
            <xsl:when test="$PreviousFormID!=''">
              <xsl:value-of
                select="concat($PreviousFormCode,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$PreviousFormCode and (not(@SetNumber) or @SetNumber=$PreviousFormPos)]/@ID))"
              />
            </xsl:when>
            <xsl:otherwise/>
          </xsl:choose>
        </xsl:variable>
        <xsl:for-each
          select="/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$ThisFormCode and @Selected='true' and @ParentID=$MiniEditorExistParentID]">
          <xsl:variable name="ThisPackPos" select="position()"/>
          <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
            <xsl:call-template name="FormCopy">
              <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
              <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
              <xsl:with-param name="ThisFormSelected" select="'true'"/>
              <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
              <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
            </xsl:call-template>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:when>
      <!-- Вариант ГКН -->
      <!-- Межевой план -->
      <xsl:when test="/MiniEditor/Pack[//Requests_GZK_Realty and //STD_MP]">
        <xsl:choose>
          <xsl:when test="$PreviousFormID=''">
            <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
              <xsl:call-template name="FormCopy">
                <xsl:with-param name="ThisFormPos" select="1"/>
                <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                <xsl:with-param name="ThisFormSelected" select="'true'"/>
                <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$ThisFormCode='OLZ'">
            <xsl:for-each select="/MiniEditor/Pack//Requests_GZK_Realty//Parcel[@exist='yes']">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$ThisFormCode='MDZ'">
            <xsl:for-each select="/MiniEditor/Pack//STD_MP//ChangeParcel">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$ThisFormCode='MDZPart'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//ChangeParcel[$PreviousFormPos]//SubParcel">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$ThisFormCode='NWZ'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel']">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$ThisFormCode='NWZPart'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'][$PreviousFormPos]//SubParcel">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$ThisFormCode='CHZ'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel']">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
            <xsl:if test="count(/MiniEditor/Pack//STD_MP//NewSubParcel)>0">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:if>
          </xsl:when>

          <xsl:when test="$ThisFormCode='CHZPart'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'][$PreviousFormPos]//SubParcel">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
            <xsl:for-each select="/MiniEditor/Pack//STD_MP//NewSubParcel">
              <xsl:variable name="ThisPackPos" select="position()"/>
              <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                <xsl:call-template name="FormCopy">
                  <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                  <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                  <xsl:with-param name="ThisFormSelected" select="'true'"/>
                  <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                  <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$ThisFormCode='NBZ'">
            <xsl:choose>
              <xsl:when test="$VersionRequestFrom='12' or $VersionRequestFrom='14'">
                <xsl:for-each select="/MiniEditor/Pack//STD_MP//SpecifyRelatedParcel">
                  <xsl:variable name="ThisPackPos" select="position()"/>
                  <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                    <xsl:call-template name="FormCopy">
                      <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                      <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                      <xsl:with-param name="ThisFormSelected" select="'true'"/>
                      <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                      <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                    </xsl:call-template>
                  </xsl:for-each>
                </xsl:for-each>
              </xsl:when>
              <xsl:when test="$VersionRequestFrom='15'">
                <xsl:for-each
                  select="/MiniEditor/Pack//Requests_GZK_Realty//Parcel[@exist='neighbour']">
                  <xsl:variable name="ThisPackPos" select="position()"/>
                  <xsl:for-each select="/MiniEditor/Forms/Form[(@Code=$ThisFormCode)]">
                    <xsl:call-template name="FormCopy">
                      <xsl:with-param name="ThisFormPos" select="$ThisPackPos"/>
                      <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
                      <xsl:with-param name="ThisFormSelected" select="'true'"/>
                      <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
                      <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
                    </xsl:call-template>
                  </xsl:for-each>
                </xsl:for-each>
              </xsl:when>
            </xsl:choose>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="@Selected='true'">
          <xsl:call-template name="FormCopy">
            <xsl:with-param name="ThisFormPos" select="1"/>
            <xsl:with-param name="ThisFormCode" select="$ThisFormCode"/>
            <xsl:with-param name="ThisFormSelected" select="'true'"/>
            <xsl:with-param name="PreviousFormID" select="$PreviousFormID"/>
            <xsl:with-param name="PreviousFormCode" select="$PreviousFormCode"/>
          </xsl:call-template>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Необязательные разделы @Modal="Optional" или "ConditionalOptional": вычисление значения Selected (надо менять - для всех таких разделов) -->
  <xsl:template name="ModalCode">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <!-- Конкретный раздел @Modal="Optional" или "ConditionalOptional" -->
    <xsl:choose>
      <!-- Вариант Any -->
      <xsl:when test="$Variant='Any'">
        <xsl:value-of
          select="count(
                      //Pack[$FormPos1=0]//Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]
                      | //Pack[$FormPos1!=0]//Form[@Code=$FormCode1][position()=$FormPos1]/Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]
                      )>0"
        />
      </xsl:when>
      <!-- Вариант MiniEditorExist -->
      <xsl:when test="$MiniEditorExist='true'">
        <xsl:value-of
          select="count(
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode and @Selected='true']
                      )>0"
        />
      </xsl:when>
      <!-- Вариант ГКН -->
      <!-- Заявление -->
      <xsl:when
        test="$FormCode='Request' and $PageCode='Applied_Documents' and $PartCode='Applied_Document'">
        <xsl:value-of
          select="count(
                      /MiniEditor/Pack//Requests_GZK_Realty//Applied_Documents
                      /Applied_Document[(Code_Document!='558100000000' and Code_Document!='558101010000' and Code_Document!='558101020000' and Code_Document!='558101030000' and Code_Document!='558301010000' and Code_Document!='558203000000' and ($VersionRequestFrom='14' or $VersionRequestFrom='15')) or (Kind!='008' and Kind!='009' and Kind!='019' and $VersionRequestFrom='12')])>0"/>
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='Applied_Documents' and $PartCode='Payment_Document'">
        <xsl:value-of
          select="count( /MiniEditor/Pack//Requests_GZK_Realty//Payment_Documents/Payment_Document)>0"
        />
      </xsl:when>
      <!-- RequestText -->
      <xsl:when
        test="$FormCode='Request' and $PageCode='RequestText' and $PartCode='RequestText'">
        <xsl:value-of select="count(/MiniEditor/Pack//Requests_GZK_Realty//Request_Text)>0"/>
      </xsl:when>
      <!-- Межевой план -->
      <!--MP-->
      <xsl:when
        test="$FormCode='MP' and $PageCode='BasicData' and $PartCode='Coord_System'">
        <xsl:value-of select="count(/MiniEditor/Pack//STD_MP//Coord_Systems/Coord_System)>0"/>
      </xsl:when>
      <!--OLZ-->
      <xsl:when
        test="$FormCode='OLZ' and $PageCode='SubParcels' and $PartCode='SubParcel'">
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Object/Parcels/Parcel[position()=$FormPos]">
          <xsl:value-of select="count(SubParcels/SubParcel)>0"/>
        </xsl:for-each>
      </xsl:when>
      <!--NWZ-->
      <xsl:when test="$FormCode='NWZ' and $PageCode='Category'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]">
          <xsl:choose>
            <xsl:when test="$PartCode='Providing_Pass_CadastralNumbers'">
              <xsl:value-of select="count(Providing_Pass_CadastralNumbers/CadastralNumber)>0"/>
            </xsl:when>
            <xsl:when test="$PartCode='Inner_CadastralNumbers'">
              <xsl:value-of select="count(Inner_CadastralNumbers/CadastralNumber)>0"/>
            </xsl:when>
            <xsl:when test="$PartCode='NaturalObject'">
              <xsl:value-of select="count(NaturalObject)>0"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances'">
              <xsl:value-of select="count(Encumbrances/Encumbrance)>0"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <!--CHZ-->
      <xsl:when test="$FormCode='CHZ' and $PageCode='Category'">
        <xsl:for-each
          select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel']">
          <xsl:choose>
            <xsl:when test="$PartCode='Inner_CadastralNumbers'">
              <xsl:value-of select="count(Inner_CadastralNumbers/CadastralNumber)>0"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances'">
              <xsl:value-of select="count(Encumbrances/Encumbrance)>0"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <!--MDZ-->
      <!--MDZPart-->
      <!--NBZ-->
      <xsl:when
        test="$FormCode='NBZ' and $PageCode='Entity_Spatial' and $PartCode='Edge'">
        <xsl:for-each select="/MiniEditor/Pack//STD_MP//SpecifyRelatedParcel[position()=$FormPos]">
          <xsl:text>false</xsl:text>
        </xsl:for-each>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <!-- Необязательные разделы "ConditionalOptional": вычисление значения DefaultConditionTrue (надо менять - для всех таких разделов) -->
  <xsl:template name="DefaultModalCode">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <!-- Конкретный раздел "ConditionalOptional" -->
    <xsl:choose>
      <!-- Вариант Any -->
      <xsl:when test="$Variant='Any'">
        <xsl:value-of
          select="count(
                      //Pack[$FormPos1=0]//Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]
                      | //Pack[$FormPos1!=0]//Form[@Code=$FormCode1][position()=$FormPos1]/Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]
                      )>0"
        />
      </xsl:when>
      <!-- Вариант MiniEditorExist -->
      <xsl:when test="$MiniEditorExist='true'">
        <xsl:value-of
          select="count(
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode and @DefaultConditionTrue='true']
                      )>0"
        />
      </xsl:when>
      <!-- Вариант ГКН -->
      <!-- Заявление -->
      <xsl:when
        test="$FormCode='Request' and $PageCode='Applied_Documents' and $PartCode='Applied_Document'">
        <xsl:value-of
          select="count(
                      /MiniEditor/Pack//Requests_GZK_Realty//Applied_Documents
                      /Applied_Document[(Code_Document!='558100000000' and Code_Document!='558101010000' and Code_Document!='558101020000' and Code_Document!='558101030000' and Code_Document!='558301010000' and Code_Document!='558203000000' and ($VersionRequestFrom='14' or $VersionRequestFrom='15')) or (Kind!='008' and Kind!='009' and Kind!='019' and $VersionRequestFrom='12')])>0"/>
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='Applied_Documents' and $PartCode='Payment_Document'">
        <xsl:value-of
          select="count( /MiniEditor/Pack//Requests_GZK_Realty//Payment_Documents/Payment_Document)>0"
        />
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='RequestText' and $PartCode='RequestText'">
        <xsl:value-of select="count(/MiniEditor/Pack//Requests_GZK_Realty//Request_Text)>0"/>
      </xsl:when>
      <!-- Межевой план -->
      <!--MP-->
      <xsl:when
        test="$FormCode='MP' and $PageCode='BasicData' and $PartCode='Coord_System'">
        <xsl:value-of select="count(/MiniEditor/Pack//STD_MP//Coord_Systems/Coord_System)>0"/>
      </xsl:when>
      <!--OLZ-->
      <xsl:when
        test="$FormCode='OLZ' and $PageCode='SubParcels' and $PartCode='SubParcel'">
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Object/Parcels/Parcel[position()=$FormPos]">
          <xsl:value-of select="count(SubParcels/SubParcel)>0"/>
        </xsl:for-each>
      </xsl:when>
      <!--NWZ-->
      <xsl:when test="$FormCode='NWZ' and $PageCode='Category'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]">
          <xsl:choose>
            <xsl:when test="$PartCode='Providing_Pass_CadastralNumbers'">
              <xsl:value-of select="count(Providing_Pass_CadastralNumbers/CadastralNumber)>0"/>
            </xsl:when>
            <xsl:when test="$PartCode='Inner_CadastralNumbers'">
              <xsl:value-of select="count(Inner_CadastralNumbers/CadastralNumber)>0"/>
            </xsl:when>
            <xsl:when test="$PartCode='NaturalObject'">
              <xsl:value-of select="count(NaturalObject)>0"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances'">
              <xsl:value-of select="count(Encumbrances/Encumbrance)>0"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <!--CHZ-->
      <xsl:when test="$FormCode='CHZ' and $PageCode='Category'">
        <xsl:for-each
          select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel']">
          <xsl:choose>
            <xsl:when test="$PartCode='Inner_CadastralNumbers'">
              <xsl:value-of select="count(Inner_CadastralNumbers/CadastralNumber)>0"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances'">
              <xsl:value-of select="count(Encumbrances/Encumbrance)>0"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <!--MDZ-->
      <!--MDZPart-->
      <!--NBZ-->
      <xsl:when
        test="$FormCode='NBZ' and $PageCode='Entity_Spatial' and $PartCode='Edge'">
        <xsl:for-each select="/MiniEditor/Pack//STD_MP//SpecifyRelatedParcel[position()=$FormPos]">
          <xsl:text>false</xsl:text>
        </xsl:for-each>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <!-- Секции раздела Alt: вычисление значения @Code выбранной секции, т.е. той, у которой Selected="true" (надо менять - для всех разделов Alt) -->
  <xsl:template name="AltCode">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <!-- Конкретный раздел Alt -->
    <xsl:choose>
      <!-- Вариант Any -->
      <xsl:when test="$Variant='Any'">
        <xsl:value-of
          select="(
                      //Pack[$FormPos1=0]//Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section/@Code
                      | //Pack[$FormPos1!=0]//Form[@Code=$FormCode1][position()=$FormPos1]/Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section/@Code
                      )"
        />
      </xsl:when>
      <!-- Вариант MiniEditorExist -->
      <xsl:when test="$MiniEditorExist='true'">
        <xsl:variable name="value"
          select="
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section[@Selected='true']/@Code
                      "/>
        <xsl:choose>
          <xsl:when
            test="$PageCode='Request_Documents' and $PartCode='Request_Document' and $value=''">
            <xsl:variable name="value1"
              select="
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section/ParamSelect/Param[@Selected='true']/@Code
                      "/>
            <xsl:choose>
              <xsl:when test="$value1='023'">
                <xsl:text>KV</xsl:text>
              </xsl:when>
              <xsl:when test="$value1='022'">
                <xsl:text>KP</xsl:text>
              </xsl:when>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$value"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- Вариант ГКН -->
      <!-- Заявление -->
      <xsl:when test="$FormCode='Request' and $PageCode='Declarants' and $PartCode='Delivery'">
        <xsl:choose>
          <xsl:when
            test="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Kind_Delivery='785001000000' or count(/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_OKU_BTI)>0"
            >OKU</xsl:when>
          <xsl:when
            test="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Kind_Delivery='785002000000' or /MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Way_Delivery/Kind_Mail='01'"
            >Mail</xsl:when>

        </xsl:choose>
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='Request_Documents' and $PartCode='Request_Document'">
        <xsl:choose>
          <xsl:when
            test="/MiniEditor/Pack//Requests_GZK_Realty//Request_Document[@SubCode='023' or @SubCode='558214010000']"
            >KV</xsl:when>
          <xsl:when
            test="/MiniEditor/Pack//Requests_GZK_Realty//Request_Document[@SubCode='022' or @SubCode='558213010000']"
            >KP</xsl:when>
        </xsl:choose>

      </xsl:when>
      <xsl:when test="$FormCode='Request' and $PageCode='Declarants' and $PartCode='Declarant' ">
        <!--   <xsl:choose>
          <xsl:when test="count(/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Organization)>0">J</xsl:when>
          <xsl:when test="count(/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Person)>0">F</xsl:when>
        </xsl:choose>-->
        <xsl:choose>
          <xsl:when test="$SenderTo='F'">
            <!-- отправитель физ.лицо -->
            <xsl:choose>
              <xsl:when test="$XMLDeclarant='F'">
                <!-- заявитель физ. лицо -->
                <xsl:variable name="testPerson">
                  <xsl:call-template name="CompareF"></xsl:call-template>
                </xsl:variable>
                <xsl:choose>
                  <xsl:when test="$testPerson='true'">M</xsl:when>
                  <!--1) Свое заявление отправитель физ-лицо -->
                  <xsl:otherwise>F</xsl:otherwise>
                  <!--2) Заявление от другого физ лица отправитель физ-лицо -->
                </xsl:choose>
              </xsl:when>
              <!-- заявитель юр. лицо -->
              <!-- <xsl:when test="$XMLDeclarant='J'">J</xsl:when> -->
              <xsl:when test="$XMLDeclarant='J'">
                <xsl:for-each
                  select="/MiniEditor/Pack//Requests_GZK_Realty//Organization">
                  <xsl:variable name="testOrg">
                    <xsl:call-template name="CompareJ"></xsl:call-template>
                  </xsl:variable>
                  <xsl:choose>
                    <xsl:when test="$testOrg='true'">M</xsl:when>
                    <!--1) Свое заявление отправитель физ-лицо -->
                    <xsl:otherwise>J</xsl:otherwise>
                    <!--3) Заявление от другого юр. лица отправитель физ-лицо -->
                  </xsl:choose>
                </xsl:for-each>
              </xsl:when>
            </xsl:choose>
          </xsl:when>
          <xsl:when test="$SenderTo='J'">
            <!-- отправитель юр.лицо -->
            <xsl:choose>
              <xsl:when test="$XMLDeclarant='J'">
                <!-- заявитель юр. лицо -->
                <xsl:variable name="testOrganization">
                  <xsl:call-template name="CompareJ"></xsl:call-template>
                </xsl:variable>
                <xsl:choose>
                  <xsl:when test="$testOrganization='true'">M</xsl:when>
                  <!--4) Свое заявление отправитель юр.лицо -->
                  <xsl:otherwise>J</xsl:otherwise>
                  <!--5) Заявление от другого юр лица отправитель юр-лицо -->
                </xsl:choose>

              </xsl:when>
              <!-- заявитель физ. лицо -->
              <xsl:when test="$XMLDeclarant='F'">
                <xsl:variable name="testPerson2">
                  <xsl:call-template name="CompareF"></xsl:call-template>
                </xsl:variable>
                <xsl:choose>
                  <xsl:when test="$testPerson2='true'">M</xsl:when>
                  <!--4) Свое заявление отправитель юр.лицо -->
                  <xsl:otherwise>F</xsl:otherwise>
                  <!--6) Заявление от другого физ лица отправитель юр-лицо -->
                </xsl:choose>
              </xsl:when>
            </xsl:choose>
          </xsl:when>
        </xsl:choose>

      </xsl:when>
      <!-- Межевой план -->
      <!--MP-->
      <xsl:when test="$FormCode='MP' and $PageCode='Common' and $PartCode='Method'">
        <xsl:choose>
          <xsl:when
            test="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel']/@Method!=''">
            <xsl:value-of
              select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel']/@Method"
            />
          </xsl:when>
          <xsl:when test="count(/MiniEditor/Pack//STD_MP//NewSubParcel)>0">SP0</xsl:when>
          <xsl:when test="count(/MiniEditor/Pack//STD_MP//ExistParcel)>0">SP1</xsl:when>
        </xsl:choose>


      </xsl:when>


      <!--CHZPart-->
      <xsl:when test="$FormCode='CHZPart' and $PageCode='SubParcels' and $PartCode='SubParcel'">
        <xsl:choose>
          <xsl:when
            test="/MiniEditor/Pack//STD_MP//Parcel/SubParcels/SubParcel[position()=$FormPos and @Number_PP!='']"
            >Old</xsl:when>
          <xsl:when
            test="/MiniEditor/Pack//STD_MP//Parcel/SubParcels/SubParcel[position()=$FormPos and @Definition!='']"
            >New</xsl:when>
          <xsl:when
            test="/MiniEditor/Pack//STD_MP//ExistParcel/SubParcels/SubParcel[position()=$FormPos]"
            >Old</xsl:when>
          <xsl:when test="/MiniEditor/Pack//STD_MP//NewSubParcel[position()=$FormPos]"
            >New</xsl:when>
        </xsl:choose>

      </xsl:when>

      <!--OLZ-->
      <xsl:when test="$FormCode='OLZ' and $PageCode='Parcels' and $PartCode='ParcelAddress'">
        <xsl:text>000</xsl:text>
      </xsl:when>
      <!--NWZ-->
      <xsl:when test="$FormCode='NWZ' and $PageCode='Parcels' and $PartCode='ParcelAddress'">
        <xsl:text>000</xsl:text>
      </xsl:when>
      <!--NWZPart-->
      <xsl:when test="$FormCode='NWZPart' and $PageCode='SubParcels' and $PartCode='SubParcel'">
        <xsl:text>New</xsl:text>
      </xsl:when>
      <!--MDZ-->
      <!--MDZPart-->
      <!--NBZ-->
    </xsl:choose>
  </xsl:template>

  <!-- Разделы Multi, порождение нужного числа секций Section (надо менять - для всех разделов Multi) -->
  <xsl:template name="MultiPart">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <xsl:choose>
      <!-- Конкретный раздел Multi -->
      <!-- Вариант Any -->
      <xsl:when test="$Variant='Any'">
        <xsl:for-each
          select="(
                      //Pack[$FormPos1=0]//Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section 
                      | //Pack[$FormPos1!=0]//Form[@Code=$FormCode1][position()=$FormPos1]/Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section
                      )">
          <!-- Одна секция -->
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!-- Вариант MiniEditorExist -->
      <xsl:when test="$MiniEditorExist='true'">
        <xsl:for-each
          select="
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section
                      ">
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!-- Вариант ГКН -->
      <!-- Заявление -->
      <xsl:when
        test="$FormCode='Request' and $PageCode='Applied_Documents' and $PartCode='Applied_Document' and 
        /MiniEditor/Pack//Requests_GZK_Realty//Applied_Documents/Applied_Document[(Code_Document!='558100000000' and Code_Document!='558101010000' and Code_Document!='558101020000' and Code_Document!='558101030000' and Code_Document!='558301010000' and Code_Document!='558203000000' and ($VersionRequestFrom='14' or $VersionRequestFrom='15')) or (Kind!='008' and Kind!='009' and Kind!='019' and $VersionRequestFrom='12')]">
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Applied_Documents/Applied_Document[(Code_Document!='558100000000' and Code_Document!='558101010000' and Code_Document!='558101020000' and Code_Document!='558101030000' and Code_Document!='558301010000' and Code_Document!='558203000000' and ($VersionRequestFrom='14' or $VersionRequestFrom='15')) or (Kind!='008' and Kind!='009' and Kind!='019' and $VersionRequestFrom='12')]">
          <!-- Одна секция -->
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='Applied_Documents' and $PartCode='Payment_Document' and 
        /MiniEditor/Pack//Requests_GZK_Realty//Payment_Documents/Payment_Document">
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Payment_Documents/Payment_Document">
          <!-- Одна секция -->
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='Request_Documents' and $PartCode='Request_Document' and 
                (/MiniEditor/Pack//Requests_GZK_Realty//Request_Documents/Request_Document)">
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Request_Documents/Request_Document">
          <!-- Одна секция -->
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!-- Межевой план -->
      <!--MP-->
      <!--OLZ-->
      <xsl:when
        test="$FormCode='OLZ' and $PageCode='SubParcels' and $PartCode='SubParcel' and (/MiniEditor/Pack//Requests_GZK_Realty//Object/Parcels/Parcel[position()=$FormPos]/SubParcels/SubParcel)">
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Object/Parcels/Parcel[position()=$FormPos]/SubParcels/SubParcel">
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!--CHZ-->
      <xsl:when test="$FormCode='CHZ' and $PageCode='Category'">
        <xsl:for-each
          select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel']">
          <xsl:choose>
            <xsl:when
              test="$PartCode='Inner_CadastralNumbers' and Inner_CadastralNumbers/CadastralNumber">
              <xsl:for-each select="Inner_CadastralNumbers/CadastralNumber">
                <xsl:call-template name="MultiSection">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="MultiPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances' and Encumbrances/Encumbrance">
              <xsl:for-each select="Encumbrances/Encumbrance">
                <xsl:call-template name="MultiSection">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="MultiPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <xsl:when
        test="$FormCode='CHZ' and $PageCode='Entity_Spatial' and $PartCode='Point' and 
        ((/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])//Entity_Spatial/Spatial_Element)">
        <xsl:choose>
          <xsl:when
            test="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])/Contours">
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])/Contours/Contour">
              <xsl:variable name="ContourPos" select="position()"/>
              <xsl:for-each select="Entity_Spatial/Spatial_Element">
                <!-- Один Spelement_Unit -->
                <xsl:call-template name="MultiSectionPoint">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="ContourPos" select="$ContourPos"/>
                  <xsl:with-param name="Spatial_ElementPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]/Entity_Spatial/Spatial_Element">
              <!-- Один Spelement_Unit -->
              <xsl:call-template name="MultiSectionPoint">
                <xsl:with-param name="FormCode" select="$FormCode"/>
                <xsl:with-param name="FormCode1" select="$FormCode1"/>
                <xsl:with-param name="FormPos" select="$FormPos"/>
                <xsl:with-param name="FormPos1" select="$FormPos1"/>
                <xsl:with-param name="PageCode" select="$PageCode"/>
                <xsl:with-param name="PartCode" select="$PartCode"/>
                <xsl:with-param name="ContourPos" select="0"/>
                <xsl:with-param name="Spatial_ElementPos" select="position()"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:when
        test="$FormCode='CHZ' and $PageCode='Entity_Spatial' and $PartCode='Edge' 
        and (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]//Entity_Spatial">
        <xsl:choose>
          <xsl:when
            test="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]/Contours">
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]/Contours/Contour">
              <xsl:variable name="ContourPos" select="position()"/>
              <xsl:for-each select="Entity_Spatial">
                <!-- Один Entity_Spatial -->
                <xsl:call-template name="MultiSectionEdge">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="ContourPos" select="$ContourPos"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]/Entity_Spatial">
              <!-- Один Entity_Spatial -->
              <xsl:call-template name="MultiSectionEdge">
                <xsl:with-param name="FormCode" select="$FormCode"/>
                <xsl:with-param name="FormCode1" select="$FormCode1"/>
                <xsl:with-param name="FormPos" select="$FormPos"/>
                <xsl:with-param name="FormPos1" select="$FormPos1"/>
                <xsl:with-param name="PageCode" select="$PageCode"/>
                <xsl:with-param name="PartCode" select="$PartCode"/>
                <xsl:with-param name="ContourPos" select="0"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- Контуры -->
      <xsl:when
        test="$FormCode='CHZ' and $PageCode='Entity_Spatial' and $PartCode='Square' and 
        (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]/Contours">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]/Contours/Contour">
          <!-- Одна секция -->
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!-- CHZPart -->
      <xsl:when
        test="$FormCode='CHZPart' and $PageCode='SubParcels' and $PartCode='Encumbrances' and (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel']/SubParcels/SubParcel[position()=$FormPos]/Encumbrances/Encumbrance)">
        <xsl:for-each
          select="/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel']/SubParcels/SubParcel[position()=$FormPos]/Encumbrances/Encumbrance">
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!-- Точки части участка -->
      <!--Для существующих частей-->
      <xsl:when
        test="$FormCode='CHZPart' and $PageCode='Entity_Spatial' and $PartCode='Point' and 
        (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos1]/SubParcels/SubParcel[position()=$FormPos]/Entity_Spatial/Spatial_Element">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos1]
          /SubParcels/SubParcel[position()=$FormPos]/Entity_Spatial/Spatial_Element">
          <!-- Один Spelement_Unit -->
          <xsl:call-template name="MultiSectionPoint">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="ContourPos" select="0"/>
            <xsl:with-param name="Spatial_ElementPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!--Для образующихся частей-->
      <xsl:when
        test="$FormCode='CHZPart' and $PageCode='Entity_Spatial' and $PartCode='Point' and 
        /MiniEditor/Pack//STD_MP//NewSubParcel[position()=$FormPos]/Entity_Spatial/Spatial_Element">
        <xsl:for-each
          select="/MiniEditor/Pack//STD_MP//NewSubParcel[position()=$FormPos]/Entity_Spatial/Spatial_Element">
          <!-- Один Spelement_Unit -->
          <xsl:call-template name="MultiSectionPoint">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="ContourPos" select="0"/>
            <xsl:with-param name="Spatial_ElementPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!--NWZ-->
      <xsl:when test="$FormCode='NWZ' and $PageCode='Category'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]">
          <xsl:choose>
            <xsl:when
              test="$PartCode='Providing_Pass_CadastralNumbers' and Providing_Pass_CadastralNumbers/CadastralNumber">
              <xsl:for-each select="Providing_Pass_CadastralNumbers/CadastralNumber">
                <xsl:call-template name="MultiSection">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="MultiPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
            <xsl:when
              test="$PartCode='Inner_CadastralNumbers' and Inner_CadastralNumbers/CadastralNumber">
              <xsl:for-each select="Inner_CadastralNumbers/CadastralNumber">
                <xsl:call-template name="MultiSection">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="MultiPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
            <xsl:when test="$PartCode='Utilization' and Utilization">
              <xsl:for-each select="Utilization">
                <xsl:call-template name="MultiSection">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="MultiPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances' and Encumbrances/Encumbrance">
              <xsl:for-each select="Encumbrances/Encumbrance">
                <xsl:call-template name="MultiSection">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="MultiPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="MultiSection">
                <xsl:with-param name="FormCode" select="$FormCode"/>
                <xsl:with-param name="FormCode1" select="$FormCode1"/>
                <xsl:with-param name="FormPos" select="$FormPos"/>
                <xsl:with-param name="FormPos1" select="$FormPos1"/>
                <xsl:with-param name="PageCode" select="$PageCode"/>
                <xsl:with-param name="PartCode" select="$PartCode"/>
                <xsl:with-param name="MultiPos" select="1"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <!-- Точки участка -->
      <xsl:when
        test="$FormCode='NWZ' and $PageCode='Entity_Spatial' and $PartCode='Point' and 
                ((/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]//Entity_Spatial/Spatial_Element)">
        <xsl:choose>
          <xsl:when
            test="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Contours">
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Contours/Contour">
              <xsl:variable name="ContourPos" select="position()"/>
              <xsl:for-each select="Entity_Spatial/Spatial_Element">
                <!-- Один Spelement_Unit -->
                <xsl:call-template name="MultiSectionPoint">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="ContourPos" select="$ContourPos"/>
                  <xsl:with-param name="Spatial_ElementPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Entity_Spatial/Spatial_Element">
              <!-- Один Spelement_Unit -->
              <xsl:call-template name="MultiSectionPoint">
                <xsl:with-param name="FormCode" select="$FormCode"/>
                <xsl:with-param name="FormCode1" select="$FormCode1"/>
                <xsl:with-param name="FormPos" select="$FormPos"/>
                <xsl:with-param name="FormPos1" select="$FormPos1"/>
                <xsl:with-param name="PageCode" select="$PageCode"/>
                <xsl:with-param name="PartCode" select="$PartCode"/>
                <xsl:with-param name="ContourPos" select="0"/>
                <xsl:with-param name="Spatial_ElementPos" select="position()"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- Ребра участка -->
      <xsl:when
        test="$FormCode='NWZ' and $PageCode='Entity_Spatial' and $PartCode='Edge' 
                and (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]//Entity_Spatial">
        <xsl:choose>
          <xsl:when
            test="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Contours">
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Contours/Contour">
              <xsl:variable name="ContourPos" select="position()"/>
              <xsl:for-each select="Entity_Spatial">
                <!-- Один Entity_Spatial -->
                <xsl:call-template name="MultiSectionEdge">
                  <xsl:with-param name="FormCode" select="$FormCode"/>
                  <xsl:with-param name="FormCode1" select="$FormCode1"/>
                  <xsl:with-param name="FormPos" select="$FormPos"/>
                  <xsl:with-param name="FormPos1" select="$FormPos1"/>
                  <xsl:with-param name="PageCode" select="$PageCode"/>
                  <xsl:with-param name="PartCode" select="$PartCode"/>
                  <xsl:with-param name="ContourPos" select="$ContourPos"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Entity_Spatial">
              <!-- Один Entity_Spatial -->
              <xsl:call-template name="MultiSectionEdge">
                <xsl:with-param name="FormCode" select="$FormCode"/>
                <xsl:with-param name="FormCode1" select="$FormCode1"/>
                <xsl:with-param name="FormPos" select="$FormPos"/>
                <xsl:with-param name="FormPos1" select="$FormPos1"/>
                <xsl:with-param name="PageCode" select="$PageCode"/>
                <xsl:with-param name="PartCode" select="$PartCode"/>
                <xsl:with-param name="ContourPos" select="0"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- Контуры -->
      <xsl:when
        test="$FormCode='NWZ' and $PageCode='Entity_Spatial' and $PartCode='Square' and 
                (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Contours">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Contours/Contour">
          <!-- Одна секция -->
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!--NWZPart-->
      <xsl:when
        test="$FormCode='NWZPart' and $PageCode='SubParcels' and $PartCode='Encumbrances' and((/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos1]/SubParcels/SubParcel[position()=$FormPos]/Encumbrances/Encumbrance)">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos1]/SubParcels/SubParcel[position()=$FormPos]/Encumbrances/Encumbrance">
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!-- Точки части участка -->
      <xsl:when
        test="$FormCode='NWZPart' and $PageCode='Entity_Spatial' and $PartCode='Point' and 
                (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos1]/SubParcels/SubParcel[position()=$FormPos]/Entity_Spatial/Spatial_Element">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos1]
                      /SubParcels/SubParcel[position()=$FormPos]/Entity_Spatial/Spatial_Element">
          <!-- Один Spelement_Unit -->
          <xsl:call-template name="MultiSectionPoint">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="ContourPos" select="0"/>
            <xsl:with-param name="Spatial_ElementPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <!--MDZ-->
      <!--MDZPart-->
      <!--NBZ-->
      <xsl:when
        test="$FormCode='NBZ' and $PageCode='Entity_Spatial' and $PartCode='Point' and (/MiniEditor/Pack//STD_MP//SpecifyRelatedParcel[position()=$FormPos]/ChangeBorder)">
        <xsl:for-each
          select="/MiniEditor/Pack//STD_MP//SpecifyRelatedParcel[position()=$FormPos]/ChangeBorder">
          <xsl:call-template name="MultiSection">
            <xsl:with-param name="FormCode" select="$FormCode"/>
            <xsl:with-param name="FormCode1" select="$FormCode1"/>
            <xsl:with-param name="FormPos" select="$FormPos"/>
            <xsl:with-param name="FormPos1" select="$FormPos1"/>
            <xsl:with-param name="PageCode" select="$PageCode"/>
            <xsl:with-param name="PartCode" select="$PartCode"/>
            <xsl:with-param name="MultiPos" select="position()"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <!-- Одна секция -->
        <xsl:call-template name="MultiSection">
          <xsl:with-param name="FormCode" select="$FormCode"/>
          <xsl:with-param name="FormCode1" select="$FormCode1"/>
          <xsl:with-param name="FormPos" select="$FormPos"/>
          <xsl:with-param name="FormPos1" select="$FormPos1"/>
          <xsl:with-param name="PageCode" select="$PageCode"/>
          <xsl:with-param name="PartCode" select="$PartCode"/>
          <xsl:with-param name="MultiPos" select="1"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Параметры (надо менять - для Param, ParamSelect, ParamDate, ParamFile, ParamMemo, ParamList, LinkSelect) -->
  <!-- Если ParamSelect: вычисляется значение @Code выбранного значения Param, т.е. того, у которого Selected="true" -->
  <xsl:template name="ParamValue">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <xsl:param name="AltCode"/>
    <xsl:param name="MultiPos"/>
    <xsl:param name="ParamCode"/>
    <xsl:param name="ContourPos"/>
    <xsl:param name="Spatial_ElementPos"/>
    <xsl:param name="UnitPos"/>
    <xsl:param name="ContourAdd"/>
    <!-- Конкретный параметр -->
    <xsl:choose>
      <!-- Вариант Any -->
      <xsl:when test="$Variant='Any'">
        <xsl:choose>
          <xsl:when test="local-name() = 'ParamList'">
            <xsl:for-each
              select="(
                      //Pack[$FormPos1=0]//Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/ParamList[@Code=$ParamCode] 
                      | //Pack[$FormPos1!=0]//Form[@Code=$FormCode1][position()=$FormPos1]/Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][position()=$MultiPos]/ParamList[@Code=$ParamCode]
                      )">
              <xsl:for-each select="Param">
                <Param>
                  <xsl:value-of select="."/>
                </Param>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of
              select="(
                      //Pack[$FormPos1=0]//Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/Param[@Code=$ParamCode] 
                      | //Pack[$FormPos1!=0]//Form[@Code=$FormCode1][position()=$FormPos1]/Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][position()=$MultiPos]/Param[@Code=$ParamCode]
                      )"
            />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- Вариант MiniEditorExist -->
      <xsl:when test="$MiniEditorExist='true'">
        <xsl:choose>
          <xsl:when test="$FormCode='Info'">
            <xsl:apply-templates select="node()"/>
          </xsl:when>
          <xsl:when test="local-name()='Param' or local-name()='ParamMemo' or local-name()='ParamDate'">
            <xsl:variable name="value"
              select="
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/*[@Code=$ParamCode]
                      "/>
            <xsl:value-of select="$value"/>
          </xsl:when>
          <xsl:when test="local-name()='ParamFile'">
            <xsl:variable name="value"
              select="
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/*[@Code=$ParamCode or ($ParamCode='DocRequest' and @Code='Doc')]
                      "/>
            <xsl:value-of select="$value"/>
          </xsl:when>
          <xsl:when test="local-name()='ParamSelect'">
            <xsl:variable name="value"
              select="
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/*[@Code=$ParamCode]/*[@Selected='true']/@Code
                      "/>
            <xsl:choose>
              <xsl:when test="$PartCode='Applied_Document' and $ParamCode='Kind'">
                <xsl:call-template name="Trans">
                  <xsl:with-param name="dict">
                    <xsl:call-template name="TAppliedDocuments"/>
                  </xsl:with-param>
                  <xsl:with-param name="x" select="$value"/>
                  <xsl:with-param name="in" select="$VersionRequestFrom"/>
                  <xsl:with-param name="out" select="$VersionRequestTo"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Type'">
                <xsl:call-template name="Trans">
                  <xsl:with-param name="dict">
                    <xsl:call-template name="TEncumbranches"/>
                  </xsl:with-param>
                  <xsl:with-param name="x" select="$value"/>
                  <xsl:with-param name="in" select="$VersionMPFrom"/>
                  <xsl:with-param name="out" select="$VersionMPTo"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="$PartCode='Request_Document' and $ParamCode='SubCode'">
                <xsl:call-template name="Trans">
                  <xsl:with-param name="dict">
                    <xsl:call-template name="TRequest_Document"/>
                  </xsl:with-param>
                  <xsl:with-param name="x" select="$value"/>
                  <xsl:with-param name="in" select="$VersionRequestFrom"/>
                  <xsl:with-param name="out" select="$VersionRequestTo"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when
                test="$PartCode='Request_Document' and $AltCode='KV' and $ParamCode='PurposeKind' and $VersionRequestFrom='15' and $CodeReg='exz'">
                <xsl:variable name="testKV">
                  <!-- создаем строку содержащую цифры с разделами КВ например: |1234| -->
                  <xsl:text>|</xsl:text>
                  <xsl:for-each
                    select="/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form//ParamList[@Code='Sections_KV']/Param">
                    <xsl:value-of select="substring-after(.,'КВ.')"/>
                  </xsl:for-each>
                  <xsl:text>|</xsl:text>
                </xsl:variable>
                <xsl:variable name="kv1">
                  <xsl:value-of
                    select="(substring-after($testKV,'1')!='' or substring-before($testKV,'1')!='')"
                  />
                </xsl:variable>
                <xsl:variable name="kv2">
                  <xsl:value-of
                    select="(substring-after($testKV,'2')!='' or substring-before($testKV,'2')!='')"
                  />
                </xsl:variable>
                <xsl:variable name="kv3">
                  <xsl:value-of
                    select="(substring-after($testKV,'3')!='' or substring-before($testKV,'3')!='')"
                  />
                </xsl:variable>
                <xsl:variable name="kv4">
                  <xsl:value-of
                    select="(substring-after($testKV,'4')!='' or substring-before($testKV,'4')!='')"
                  />
                </xsl:variable>
                <xsl:variable name="kv5">
                  <xsl:value-of
                    select="(substring-after($testKV,'5')!='' or substring-before($testKV,'5')!='')"
                  />
                </xsl:variable>
                <xsl:variable name="kv6">
                  <xsl:value-of
                    select="(substring-after($testKV,'6')!='' or substring-before($testKV,'6')!='')"
                  />
                </xsl:variable>
                <xsl:choose>
                  <xsl:when test="$kv6='true'">007</xsl:when>
                  <!-- любой раздел и кв.6 (кв.1-кв.6) -->
                  <xsl:when
                    test="$kv1='true' and $kv2='false' and $kv3='false' and $kv4='false' and $kv5='false' and $kv6='false'"
                    >006</xsl:when>
                  <!-- только кв.1 -->
                  <xsl:otherwise>008</xsl:otherwise>
                  <!--КВ.1-КВ.5 -->
                </xsl:choose>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="$value"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <!--     <xsl:when test="$FormCode='Request' and $PageCode='Request_Documents' and $AltCode='KV' and $PartCode='Request_Document'">-->
          <xsl:when test="local-name() = 'ParamList'">
            <xsl:choose>
              <xsl:when test="@Code='Sections_KV' and $VersionRequestFrom!='15'">
                <xsl:variable name="PurposeKind">
                  <xsl:value-of
                    select="/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form//Page[@Code='Request_Documents']//ParamSelect[@Code='PurposeKind']/Param[@Selected='true']/@Code"
                  />
                </xsl:variable>
                <xsl:choose>
                  <xsl:when test="$PurposeKind='006'">
                    <Param>КВ.1</Param>
                  </xsl:when>
                  <xsl:when test="$PurposeKind='007'">
                    <Param>КВ.1</Param>
                    <Param>КВ.2</Param>
                    <Param>КВ.3</Param>
                    <Param>КВ.4</Param>
                    <Param>КВ.5</Param>
                    <Param>КВ.6</Param>
                  </xsl:when>
                  <xsl:when test="$PurposeKind='008'">
                    <Param>КВ.1</Param>
                    <Param>КВ.2</Param>
                    <Param>КВ.3</Param>
                    <Param>КВ.4</Param>
                    <Param>КВ.5</Param>
                  </xsl:when>
                </xsl:choose>

              </xsl:when>
              <xsl:otherwise>
                <xsl:for-each
                  select="
                  /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                  Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                  @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                  ][position()=$FormPos]
                  /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/*[@Code=$ParamCode]
                  "/>
                <xsl:for-each select="Param">
                  <Param>
                    <xsl:value-of select="."/>
                  </Param>
                </xsl:for-each>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:when test="local-name() = 'LinkSelect'">
            <xsl:variable name="LinkSelectId"
              select="
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/*[@Code=$ParamCode]
                      "/>
            <xsl:variable name="LinkSelectForm">
              <xsl:for-each select="/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form">
                <xsl:if test="@SetID = $LinkSelectId">
                  <xsl:value-of select="@Code"/>
                </xsl:if>
              </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="LinkSelectSetNumber">
              <xsl:for-each select="/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form">
                <xsl:if test="@SetID = $LinkSelectId">
                  <xsl:value-of select="@SetNumber"/>
                </xsl:if>
              </xsl:for-each>
            </xsl:variable>
            <xsl:value-of select="$LinkSelectForm"/>
            <xsl:value-of select="'1.'"/>
            <xsl:choose>
              <xsl:when test="$LinkSelectSetNumber!=''">
                <xsl:value-of select="$LinkSelectSetNumber"/>
              </xsl:when>
              <xsl:otherwise>1</xsl:otherwise>
            </xsl:choose>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <!-- Вариант ГКН -->
      <!-- Заявление -->
      <!-- Пример работы с параметрами Alt-части: в test указывается $AltCode;
      Пример работы с параметрами ParamSelect: вычисляется значение @Code выбранного значения Param, т.е. того, у которого Selected="true" -->
      <xsl:when
        test="$FormCode='Request' and $PageCode='Declarants' and $PartCode='Delivery' and $AltCode='Mail' and $ParamCode='Recipient' and /MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Way_Delivery/Recipient">
        <xsl:value-of
          select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Way_Delivery/Recipient"
        />
      </xsl:when>
      <!-- Пример работы с параметрами Param: вычисляется значение Param -->
      <xsl:when
        test="$FormCode='Request' and $PageCode='Declarants' and $PartCode='Delivery' and $AltCode='Mail' and $ParamCode='DeliveryAddress' and /MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Way_Delivery/Address">
        <xsl:value-of
          select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Way_Delivery/Address"
        />
      </xsl:when>
      <!-- Пример работы с параметрами Multi-части: в select указывается $MultiPos -->
      <xsl:when
        test="$FormCode='Request' and $PageCode='Applied_Documents' and ($PartCode='Applied_Document' or $PartCode='Applied_DocumentMP') and (/MiniEditor/Pack//Requests_GZK_Realty//Applied_Documents/Applied_Document[((Code_Document!='558100000000' and Code_Document!='558101010000' and Code_Document!='558101020000' and Code_Document!='558101030000' and Code_Document!='558301010000' and (Code_Document!='558203000000' or $PartCode='Applied_DocumentMP') and ($VersionRequestFrom='14' or $VersionRequestFrom='15') ) or (Kind!='008' and Kind!='009' and (Kind!='019' or $PartCode='Applied_DocumentMP') and $VersionRequestFrom='12'))])[$MultiPos]">
        <xsl:for-each
          select="(/MiniEditor/Pack//Requests_GZK_Realty//Applied_Documents/Applied_Document[((Code_Document!='558100000000' and Code_Document!='558101010000' and Code_Document!='558101020000' and Code_Document!='558101030000' and Code_Document!='558301010000' and (Code_Document!='558203000000' or $PartCode='Applied_DocumentMP') and ($VersionRequestFrom='14' or $VersionRequestFrom='15') ) or (Kind!='008' and Kind!='009' and (Kind!='019' or $PartCode='Applied_DocumentMP') and $VersionRequestFrom='12'))])[$MultiPos]">
          <xsl:choose>
            <xsl:when test="$ParamCode='Kind'">
              <xsl:call-template name="Trans">
                <xsl:with-param name="dict">
                  <xsl:call-template name="TAppliedDocuments"/>
                </xsl:with-param>
                <xsl:with-param name="x">
                  <xsl:choose>
                    <xsl:when test="$VersionRequestFrom='14' or $VersionRequestFrom='15'">
                      <xsl:value-of select="Code_Document"/>
                    </xsl:when>
                    <xsl:when test="$VersionRequestFrom='12'">
                      <xsl:value-of select="Kind"/>
                    </xsl:when>
                  </xsl:choose>
                </xsl:with-param>
                <xsl:with-param name="in" select="$VersionRequestFrom"/>
                <xsl:with-param name="out" select="$VersionRequestTo"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:when test="$ParamCode='Number' or $ParamCode='Name' or $ParamCode='IssueOrgan'">
              <xsl:value-of select="*[local-name()=$ParamCode]"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Date'">
              <xsl:value-of select="Duration/Started"/>
            </xsl:when>
            <xsl:when
              test="($PartCode='Applied_Document' and $ParamCode='Pages') or ($PartCode='Applied_DocumentMP' and $ParamCode='Pages0')">
              <xsl:value-of select="Quantity/@Original_Sheet"/>
            </xsl:when>
            <!-- Пример работы с параметрами ParamFile: добавляется /MiniEditor/Pack/@TempFolder -->
            <xsl:when test="$ParamCode='Request'">
              <xsl:variable name="ParamFile">
                <xsl:value-of select="Images/Image/@Name"/>
              </xsl:variable>
              <xsl:if test="$ParamFile!=''">
                <xsl:value-of select="/MiniEditor/Pack/@TempFolder"/>
                <xsl:text>\</xsl:text>
                <xsl:value-of select="$ParamFile"/>
              </xsl:if>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='Applied_Documents' and $PartCode='Payment_Document' and /MiniEditor/Pack//Requests_GZK_Realty//Payment_Documents/Payment_Document[$MultiPos]">
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Payment_Documents/Payment_Document[$MultiPos]">
          <xsl:choose>
            <xsl:when test="$ParamCode='Doc_Type'">
              <xsl:value-of select="Doc_Type"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Number'">
              <xsl:value-of select="Number"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Date'">
              <xsl:value-of select="Date"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Sum'">
              <xsl:value-of select="Sum"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Pages'">
              <xsl:choose>
                <xsl:when test="$VersionRequestFrom='15'">
                  <xsl:value-of select="Quantity/@Original_Sheet"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:text>1</xsl:text>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$ParamCode='Request'">
              <xsl:variable name="ParamFile">
                <xsl:value-of select="Images/Image/@Name"/>
              </xsl:variable>
              <xsl:if test="$ParamFile!=''">
                <xsl:value-of select="/MiniEditor/Pack/@TempFolder"/>
                <xsl:text>\</xsl:text>
                <xsl:value-of select="$ParamFile"/>
              </xsl:if>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='Request_Documents' and  $PartCode='Request_Document' and (/MiniEditor/Pack//Requests_GZK_Realty//Request_Documents/Request_Document)[$MultiPos]">
        <xsl:choose>
          <xsl:when test="$CodeReg='exz'">
            <xsl:for-each
              select="/MiniEditor/Pack//Requests_GZK_Realty//Request_Documents/Request_Document">
              <xsl:choose>
                <xsl:when test="$ParamCode='Quantity'">
                  <xsl:value-of select="@Quantity"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Name'">
                  <xsl:value-of select="@Name"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Sections_KV'">
                  <xsl:choose>
                    <xsl:when test="$VersionRequestFrom='15'">
                      <xsl:for-each select="Sections_KV/Section_KV">
                        <xsl:variable name="kv">
                          <xsl:text>КВ.</xsl:text>
                          <xsl:value-of select="substring-after(.,'0')"/>
                        </xsl:variable>
                        <Param>
                          <xsl:value-of select="$kv"/>
                        </Param>
                      </xsl:for-each>
                    </xsl:when>
                    <xsl:when test="$VersionRequestFrom!='15'">
                      <xsl:choose>
                        <xsl:when test="@PurposeKind='006'">
                          <Param>КВ.1</Param>
                        </xsl:when>
                        <xsl:when test="@PurposeKind='007'">
                          <Param>КВ.1</Param>
                          <Param>КВ.2</Param>
                          <Param>КВ.3</Param>
                          <Param>КВ.4</Param>
                          <Param>КВ.5</Param>
                          <Param>КВ.6</Param>
                        </xsl:when>
                        <xsl:when test="@PurposeKind='008'">
                          <Param>КВ.1</Param>
                          <Param>КВ.2</Param>
                          <Param>КВ.3</Param>
                          <Param>КВ.4</Param>
                          <Param>КВ.5</Param>
                        </xsl:when>
                      </xsl:choose>
                    </xsl:when>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$AltCode='KV' and $ParamCode='PurposeText'">
                  <xsl:value-of select="@PurposeKind_Text"/>
                </xsl:when>
                <xsl:when test="$AltCode='KV' and $ParamCode='PurposeKind'">
                  <xsl:choose>
                    <xsl:when test="$VersionRequestFrom='15'">
                      <xsl:variable name="testKV">
                        <!-- создаем строку содержащую цифры с разделами КВ например: |1234| -->
                        <xsl:text>|</xsl:text>
                        <xsl:for-each select="Sections_KV/Section_KV">
                          <xsl:value-of select="substring-after(.,'0')"/>
                        </xsl:for-each>
                        <xsl:text>|</xsl:text>
                      </xsl:variable>
                      <xsl:variable name="kv1">
                        <xsl:value-of
                          select="(substring-after($testKV,'1')!='' or substring-before($testKV,'1')!='')"
                        />
                      </xsl:variable>
                      <xsl:variable name="kv2">
                        <xsl:value-of
                          select="(substring-after($testKV,'2')!='' or substring-before($testKV,'2')!='')"
                        />
                      </xsl:variable>
                      <xsl:variable name="kv3">
                        <xsl:value-of
                          select="(substring-after($testKV,'3')!='' or substring-before($testKV,'3')!='')"
                        />
                      </xsl:variable>
                      <xsl:variable name="kv4">
                        <xsl:value-of
                          select="(substring-after($testKV,'4')!='' or substring-before($testKV,'4')!='')"
                        />
                      </xsl:variable>
                      <xsl:variable name="kv5">
                        <xsl:value-of
                          select="(substring-after($testKV,'5')!='' or substring-before($testKV,'5')!='')"
                        />
                      </xsl:variable>
                      <xsl:variable name="kv6">
                        <xsl:value-of
                          select="(substring-after($testKV,'6')!='' or substring-before($testKV,'6')!='')"
                        />
                      </xsl:variable>
                      <xsl:choose>
                        <xsl:when test="$kv6='true'">007</xsl:when>
                        <!-- любой раздел и кв.6 (кв.1-кв.6) -->
                        <xsl:when
                          test="$kv1='true' and $kv2='false' and $kv3='false' and $kv4='false' and $kv5='false' and $kv6='false'"
                          >006</xsl:when>
                        <!-- только кв.1 -->
                        <xsl:otherwise>008</xsl:otherwise>
                        <!--КВ.1-КВ.5 -->
                      </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="@PurposeKind"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$CodeReg='ext'">
            <xsl:for-each
              select="/MiniEditor/Pack//Requests_GZK_Realty//Request_Documents/Request_Document">
              <xsl:choose>
                <xsl:when test="$ParamCode='PurposeKind'">
                  <xsl:value-of select="@PurposeKind"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Quantity'">
                  <xsl:value-of select="@Quantity"/>
                </xsl:when>
                <xsl:when test="$ParamCode='PurposeText'">
                  <xsl:value-of select="@PurposeKind_Text"/>
                </xsl:when>
                <xsl:when test="$ParamCode='SubCode'">
                  <xsl:call-template name="Trans">
                    <xsl:with-param name="x" select="@SubCode"/>
                    <xsl:with-param name="dict">
                      <xsl:call-template name="TRequest_Document"/>
                    </xsl:with-param>
                    <xsl:with-param name="in" select="$VersionRequestFrom"/>
                    <xsl:with-param name="out" select="$VersionRequestTo"/>
                  </xsl:call-template>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each
              select="(/MiniEditor/Pack//Requests_GZK_Realty//Request_Documents/Request_Document)[$MultiPos]">
              <xsl:choose>
                <!-- Пример работы с параметрами LinkSelect: вычисляется SetID искомого объекта -->
                <xsl:when test="$ParamCode='object_id'">
                  <xsl:variable name="Request_DocumentId" select="@object_id"/>
                  <xsl:variable name="ObjectPos">
                    <xsl:for-each
                      select="/MiniEditor/Pack//Requests_GZK_Realty//Object/Parcels/Parcel[@exist='no']">
                      <xsl:if test="@temp_id = $Request_DocumentId">
                        <xsl:value-of select="position()"/>
                      </xsl:if>
                    </xsl:for-each>
                  </xsl:variable>
                  <xsl:value-of select="concat('NWZ1.',$ObjectPos)"/>
                </xsl:when>
                <xsl:when test="$ParamCode='SubCode'">
                  <xsl:call-template name="Trans">
                    <xsl:with-param name="x" select="@SubCode"/>
                    <xsl:with-param name="dict">
                      <xsl:call-template name="TRequest_Document"/>
                    </xsl:with-param>
                    <xsl:with-param name="in" select="$VersionRequestFrom"/>
                    <xsl:with-param name="out" select="$VersionRequestTo"/>
                  </xsl:call-template>
                </xsl:when>
                <xsl:when test="$ParamCode='Quantity'">
                  <xsl:value-of select="@Quantity"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:when test="$FormCode='Request' and $PageCode='Objects'">
        <xsl:for-each select="/MiniEditor/Pack//Requests_GZK_Realty//Parcel">
          <xsl:choose>
            <xsl:when test="$PartCode='Parcel' and $ParamCode='CadastralNumber'">
              <xsl:value-of select="CadastralNumber"/>
            </xsl:when>
            <xsl:when test="$PartCode='Parcel' and $ParamCode='Name'">
              <xsl:value-of select="@Name"/>
            </xsl:when>
            <xsl:when test="$PartCode='ParcelAddress' and $ParamCode='Address'">
              <xsl:value-of select="Location/Note"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
        <xsl:for-each select="/MiniEditor/Pack//Requests_GZK_Realty//Block">
          <xsl:choose>
            <xsl:when test="$PartCode='Block' and $ParamCode='CadastralNumber'">
              <xsl:value-of select="CadastralNumber"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$FormCode='Request' and $PageCode='Declarants' and $PartCode='Declarant'">
        <xsl:choose>
          <xsl:when test="$AltCode='J'">
            <xsl:for-each select="/MiniEditor/Pack//Requests_GZK_Realty//Declarant/Organization">
              <xsl:choose>
                <xsl:when test="$ParamCode='Organization'">
                  <xsl:value-of select="Name"/>
                </xsl:when>
                <xsl:when test="$ParamCode='INNJ'">
                  <xsl:value-of select="INN"/>
                </xsl:when>
                <xsl:when test="$ParamCode='KPP'">
                  <xsl:value-of select="Code_CPP"/>
                </xsl:when>
                <xsl:when test="$ParamCode='OGRN'">
                  <xsl:value-of select="Code_OGRN"/>
                </xsl:when>
                <xsl:when test="$ParamCode='RegDate'">
                  <xsl:value-of select="RegDate"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Phone'">
                  <xsl:value-of select="Phone"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Email'">
                  <xsl:value-of select="E-mail"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Address'">
                  <xsl:value-of select="Location/Note"/>
                </xsl:when>
              </xsl:choose>
              <xsl:for-each select="/MiniEditor/Pack//Requests_GZK_Realty//Agents/Agent">
                <xsl:choose>
                  <xsl:when test="$ParamCode='Agent'">
                    <xsl:value-of select="concat(FIO/Surname,' ',FIO/First,' ',FIO/Patronymic)"/>
                  </xsl:when>
                </xsl:choose>
              </xsl:for-each>
            </xsl:for-each>
            <xsl:variable name="app_numb">
              <xsl:call-template name="Trans">
                <xsl:with-param name="x" select="'009'"/>
                <xsl:with-param name="dict">
                  <xsl:call-template name="TAppliedDocuments"/>
                </xsl:with-param>
                <xsl:with-param name="in" select="'12'"/>
                <xsl:with-param name="out" select="$VersionRequestFrom"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:for-each
              select="/MiniEditor/Pack//Requests_GZK_Realty//Applied_Documents/Applied_Document">
              <xsl:if
                test="($VersionRequestFrom='12' and Kind=$app_numb) or (($VersionRequestFrom='14' or $VersionRequestFrom='15') and Code_Document=$app_numb)">
                <xsl:choose>
                  <xsl:when test="$ParamCode='LetterNumber'">
                    <xsl:value-of select="Number"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='LetterDate1'">
                    <xsl:value-of select="Duration/Started"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='LetterDate2'">
                    <xsl:value-of select="Duration/Stopped"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Request'">
                    <xsl:variable name="ParamFile">
                      <xsl:value-of select="Images/Image/@Name"/>
                    </xsl:variable>
                    <xsl:if test="$ParamFile!=''">
                      <xsl:value-of select="/MiniEditor/Pack/@TempFolder"/>
                      <xsl:text>\</xsl:text>
                      <xsl:value-of select="$ParamFile"/>
                    </xsl:if>
                  </xsl:when>
                </xsl:choose>
              </xsl:if>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$AltCode='F'">
            <xsl:for-each select="/MiniEditor/Pack//Requests_GZK_Realty//Declarant/Person">
              <xsl:choose>
                <xsl:when test="$ParamCode='FIO1'">
                  <xsl:value-of select="FIO/Surname"/>
                </xsl:when>
                <xsl:when test="$ParamCode='FIO2'">
                  <xsl:value-of select="FIO/First"/>
                </xsl:when>
                <xsl:when test="$ParamCode='FIO3'">
                  <xsl:value-of select="FIO/Patronymic"/>
                </xsl:when>
                <xsl:when test="$ParamCode='INNF'">
                  <xsl:value-of select="INN"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Phone'">
                  <xsl:value-of select="Phone"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Email'">
                  <xsl:value-of select="E-mail"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Address'">
                  <xsl:value-of select="Location/Note"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Type_Document'">
                  <xsl:call-template name="Trans">
                    <!-- временно -->
                    <xsl:with-param name="in" select="$VersionRequestFrom"/>
                    <xsl:with-param name="out" select="$VersionRequestTo"/>
                    <xsl:with-param name="x">
                      <xsl:choose>
                        <xsl:when test="$VersionRequestFrom='12'">
                          <xsl:value-of select="Document/Type_Document"/>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:value-of select="Document/Code_Document"/>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:with-param>
                    <xsl:with-param name="dict">
                      <xsl:call-template name="TType_Document"/>
                    </xsl:with-param>
                  </xsl:call-template>
                </xsl:when>
                <xsl:when test="$ParamCode='Series'">
                  <xsl:value-of select="Document/Series"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Number'">
                  <xsl:value-of select="Document/Number"/>
                </xsl:when>
                <xsl:when test="$ParamCode='IssueOrgan'">
                  <xsl:value-of select="Document/IssueOrgan"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Date'">
                  <xsl:value-of select="Document/Date"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
            <xsl:for-each select="/MiniEditor/Pack//Requests_GZK_Realty//Agents/Agent">
              <xsl:choose>
                <xsl:when test="$ParamCode='Agent'">
                  <xsl:value-of select="concat(FIO/Surname,' ',FIO/First,' ',FIO/Patronymic)"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
            <xsl:variable name="app_numb">
              <xsl:call-template name="Trans">
                <xsl:with-param name="x" select="'009'"/>
                <xsl:with-param name="dict">
                  <xsl:call-template name="TAppliedDocuments"/>
                </xsl:with-param>
                <xsl:with-param name="in" select="'12'"/>
                <xsl:with-param name="out" select="$VersionRequestFrom"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:for-each
              select="/MiniEditor/Pack//Requests_GZK_Realty//Applied_Documents/Applied_Document">
              <xsl:if
                test="($VersionRequestFrom='12' and Kind=$app_numb) or (($VersionRequestFrom='14' or $VersionRequestFrom='15') and Code_Document=$app_numb)">
                <xsl:choose>
                  <xsl:when test="$ParamCode='LetterNumber'">
                    <xsl:value-of select="Number"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='LetterDate1'">
                    <xsl:value-of select="Duration/Started"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='LetterDate2'">
                    <xsl:value-of select="Duration/Stopped"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Request'">
                    <xsl:variable name="ParamFile">
                      <xsl:value-of select="Images/Image/@Name"/>
                    </xsl:variable>
                    <xsl:if test="$ParamFile!=''">
                      <xsl:value-of select="/MiniEditor/Pack/@TempFolder"/>
                      <xsl:text>\</xsl:text>
                      <xsl:value-of select="$ParamFile"/>
                    </xsl:if>
                  </xsl:when>
                </xsl:choose>
              </xsl:if>
            </xsl:for-each>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <xsl:when
        test="$FormCode='Request' and $PageCode='RequestText' and $PartCode='RequestText' and $ParamCode='RequestText'">
        <xsl:value-of select="/MiniEditor/Pack//Requests_GZK_Realty//Request_Text"/>
      </xsl:when>
      <!-- Межевой план -->
      <!--MP-->
      <xsl:when
        test="$FormCode='MP' and $PageCode='Common' and $ParamCode='CadastralNumber' and $PartCode='Block'">
        <xsl:choose>
          <xsl:when test="$VersionMPFrom='01'">
            <xsl:value-of select="/MiniEditor/Pack//STD_MP//Cadastral_Block/@CadastralNumber"/>
          </xsl:when>
          <xsl:when test="$VersionMPFrom='02'">
            <xsl:value-of select="/MiniEditor/Pack//STD_MP//CadastralBlock"/>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <xsl:when
        test="$FormCode='MP' and $PageCode='BasicData' and $PartCode='Coord_System' and $ParamCode='Name'">
        <xsl:value-of select="/MiniEditor/Pack//STD_MP//Coord_Systems/Coord_System/@Name"/>
      </xsl:when>
      <!--CHZ-->
      <xsl:when test="$FormCode='CHZ'">
        <xsl:choose>
          <xsl:when test="$PageCode='Parcels' and $PartCode='Parcel'">
            <xsl:for-each
              select="(/MiniEditor/Pack//Requests_GZK_Realty//Object/Parcels/Parcel)[position()=$FormPos]">
              <xsl:if test="@exist='yes'">
                <xsl:choose>
                  <xsl:when test="$ParamCode='CadastralNumber'">
                    <xsl:value-of select="CadastralNumber"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Name'">
                    <xsl:value-of select="@Name"/>
                  </xsl:when>
                </xsl:choose>
              </xsl:if>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$PageCode='Category'">
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]">
              <xsl:choose>
                <xsl:when
                  test="$PartCode='Inner_CadastralNumbers' and $ParamCode='Inner_CadastralNumber'">
                  <xsl:value-of select="Inner_CadastralNumbers/CadastralNumber[$MultiPos]"/>
                </xsl:when>
                <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Name'">
                  <xsl:value-of select="Encumbrances/Encumbrance[$MultiPos]/Name"/>
                </xsl:when>
                <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Type'">
                  <xsl:value-of select="Encumbrances/Encumbrance[$MultiPos]/Type"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$PageCode='Entity_Spatial' and $PartCode='Point'">
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])">
              <xsl:for-each
                select="
                (Contours/Contour[$ContourPos]/Entity_Spatial/Spatial_Element[$Spatial_ElementPos]/Spelement_Unit[$UnitPos] |
                Entity_Spatial/Spatial_Element[$Spatial_ElementPos]/Spelement_Unit[$UnitPos])">
                <xsl:choose>
                  <xsl:when test="$ParamCode='Point_Pref'">
                    <xsl:value-of select="Ordinate/@Point_Pref"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Num_Geopoint'">
                    <xsl:value-of select="Ordinate/@Num_Geopoint"/>
                    <xsl:value-of select="$ContourAdd"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='X0'">-</xsl:when>
                  <xsl:when test="$ParamCode='Y0'">-</xsl:when>
                  <xsl:when test="$ParamCode='X'">
                    <xsl:value-of select="Ordinate/@X"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Y'">
                    <xsl:value-of select="Ordinate/@Y"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Delta_Geopoint'">
                    <xsl:value-of select="Ordinate/@Delta_Geopoint"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Geopoint_Zacrep'">
                    <xsl:value-of select="Ordinate/@Geopoint_Zacrep"/>
                  </xsl:when>
                </xsl:choose>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$PageCode='Entity_Spatial' and $PartCode='Edge'">
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]">
              <xsl:for-each
                select="
                (Contours/Contour[$ContourPos]/Entity_Spatial/Borders/Border[$UnitPos] |
                Entity_Spatial/Borders/Border[$UnitPos])">
                <xsl:choose>
                  <xsl:when test="$ParamCode='FromTo'">
                    <xsl:value-of select="@Point1"/>
                    <xsl:text>-</xsl:text>
                    <xsl:value-of select="@Point2"/>
                    <xsl:value-of select="$ContourAdd"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Length'">
                    <xsl:value-of select="Edge/Length"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Definition'">
                    <xsl:value-of select="Edge/Definition"/>
                  </xsl:when>
                </xsl:choose>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when
            test="$PageCode='Entity_Spatial' and $PartCode='Square' and 
            (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]/Contours">
            <xsl:for-each
              select="((/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]/Contours/Contour)[$MultiPos]">
              <xsl:choose>
                <xsl:when test="$ParamCode='Contour'">
                  <xsl:text>(</xsl:text>
                  <xsl:value-of select="$MultiPos"/>
                  <xsl:text>)</xsl:text>
                </xsl:when>
                <xsl:when test="$ParamCode='Definition'">
                  <xsl:value-of select="@Definition"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Area'">
                  <xsl:value-of select=".//Area/Area"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Formula'">
                  <xsl:text>S(</xsl:text>
                  <xsl:value-of select="$MultiPos"/>
                  <xsl:text>)=</xsl:text>
                  <xsl:value-of select=".//Area/Area"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>

          <xsl:when test="$PageCode='Areas' and $PartCode='Area'">
            <xsl:for-each
              select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='ExistParcel'])[position()=$FormPos]">
              <xsl:choose>
                <xsl:when test="$ParamCode='Area'">
                  <xsl:value-of select=".//Area/Area"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Innccuracy'">
                  <xsl:value-of select=".//Area/Innccuracy"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <!-- CHZPart -->
      <xsl:when test="$FormCode='CHZPart'">
        <xsl:choose>
          <xsl:when test="$PageCode='SubParcels' and $VersionMPFrom='01'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//Parcel/SubParcels/SubParcel[position()=$FormPos]">
              <xsl:choose>
                <xsl:when
                  test="$PartCode='SubParcel' and $AltCode='New' and $ParamCode='Designation'">
                  <xsl:variable name="TestDefinition">
                    <xsl:value-of select="@Definition"/>
                  </xsl:variable>
                  <xsl:choose>
                    <xsl:when test="substring($TestDefinition,1,3)='чзу'">
                      <xsl:value-of select="$TestDefinition"/>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="substring-after($TestDefinition,'/')"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$PartCode='SubParcel' and $AltCode='Old' and $ParamCode='Ord_Num'">
                  <xsl:value-of select="@Number_PP"/>
                </xsl:when>
                <xsl:when test="$PartCode='Encumbrances'">
                  <xsl:for-each select="Encumbrances/Encumbrance[$MultiPos]">
                    <xsl:choose>
                      <xsl:when test="$ParamCode='Name'">
                        <xsl:value-of select="Name"/>
                      </xsl:when>
                      <xsl:when test="$ParamCode='Type'">
                        <xsl:call-template name="Trans">
                          <xsl:with-param name="in" select="$VersionMPFrom"/>
                          <xsl:with-param name="out" select="$VersionMPTo"/>
                          <xsl:with-param name="dict">
                            <xsl:call-template name="TEncumbranches"/>
                          </xsl:with-param>
                          <xsl:with-param name="x" select="Type"/>
                        </xsl:call-template>
                      </xsl:when>
                    </xsl:choose>
                  </xsl:for-each>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$PageCode='SubParcels' and $VersionMPFrom='02'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//ExistParcel/SubParcels/SubParcel[position()=$FormPos]">
              <xsl:choose>
                <xsl:when test="$PartCode='SubParcel' and $AltCode='Old' and $ParamCode='Ord_Num'">
                  <xsl:value-of select="@Number_PP"/>
                </xsl:when>
                <xsl:when test="$PartCode='Encumbrances'">
                  <xsl:for-each select="Encumbrance">
                    <xsl:choose>
                      <xsl:when test="$ParamCode='Name'">
                        <xsl:value-of select="Name"/>
                      </xsl:when>
                      <xsl:when test="$ParamCode='Type'">
                        <xsl:call-template name="Trans">
                          <xsl:with-param name="in" select="$VersionMPFrom"/>
                          <xsl:with-param name="out" select="$VersionMPTo"/>
                          <xsl:with-param name="dict">
                            <xsl:call-template name="TEncumbranches"/>
                          </xsl:with-param>
                          <xsl:with-param name="x" select="Type"/>
                        </xsl:call-template>
                      </xsl:when>
                    </xsl:choose>
                  </xsl:for-each>

                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
            <xsl:for-each select="/MiniEditor/Pack//STD_MP//NewSubParcel[position()=$FormPos]">
              <xsl:choose>
                <xsl:when
                  test="$PartCode='SubParcel' and $AltCode='New' and $ParamCode='Designation'">
                  <xsl:variable name="TestDefinition">
                    <xsl:value-of select="@Definition"/>
                  </xsl:variable>
                  <xsl:choose>
                    <xsl:when test="substring($TestDefinition,1,3)='чзу'">
                      <xsl:value-of select="$TestDefinition"/>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:value-of select="substring-after($TestDefinition,'/')"/>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$PartCode='Encumbrances'">
                  <xsl:for-each select="Encumbrance">
                    <xsl:choose>
                      <xsl:when test="$ParamCode='Name'">
                        <xsl:value-of select="Name"/>
                      </xsl:when>
                      <xsl:when test="$ParamCode='Type'">
                        <xsl:call-template name="Trans">
                          <xsl:with-param name="in" select="$VersionMPFrom"/>
                          <xsl:with-param name="out" select="$VersionMPTo"/>
                          <xsl:with-param name="dict">
                            <xsl:call-template name="TEncumbranches"/>
                          </xsl:with-param>
                          <xsl:with-param name="x" select="Type"/>
                        </xsl:call-template>
                      </xsl:when>
                    </xsl:choose>
                  </xsl:for-each>
                </xsl:when>
                <xsl:when test="$PartCode='SubParcel_Realty'">
                  <xsl:value-of select="@SubParcel_Realty"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$PageCode='Entity_Spatial' and $PartCode='Point' and $VersionMPFrom='01'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//Parcel[position()=$FormPos1]/SubParcels/SubParcel[position()=$FormPos]">
              <xsl:for-each
                select="Entity_Spatial/Spatial_Element[$Spatial_ElementPos]/Spelement_Unit[$UnitPos]">
                <xsl:choose>
                  <xsl:when test="$ParamCode='Point_Pref'">
                    <xsl:value-of select="Ordinate/@Point_Pref"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Num_Geopoint'">
                    <xsl:value-of select="Ordinate/@Num_Geopoint"/>
                    <xsl:value-of select="$ContourAdd"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='X'">
                    <xsl:value-of select="Ordinate/@X"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Y'">
                    <xsl:value-of select="Ordinate/@Y"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Delta_Geopoint'">
                    <xsl:value-of select="Ordinate/@Delta_Geopoint"/>
                  </xsl:when>
                </xsl:choose>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$PageCode='Entity_Spatial' and $PartCode='Point' and $VersionMPFrom='02'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//ExistParcel/SubParcels/SubParcel[position()=$FormPos]">
              <xsl:for-each
                select="Entity_Spatial/Spatial_Element[$Spatial_ElementPos]/Spelement_Unit[$UnitPos]">
                <xsl:choose>
                  <xsl:when test="$ParamCode='Point_Pref'">
                    <xsl:value-of select="Ordinate/@Point_Pref"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Num_Geopoint'">
                    <xsl:value-of select="Ordinate/@Num_Geopoint"/>
                    <xsl:value-of select="$ContourAdd"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='X'">
                    <xsl:value-of select="Ordinate/@X"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Y'">
                    <xsl:value-of select="Ordinate/@Y"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Delta_Geopoint'">
                    <xsl:value-of select="Ordinate/@Delta_Geopoint"/>
                  </xsl:when>
                </xsl:choose>
              </xsl:for-each>
            </xsl:for-each>
            <xsl:for-each select="/MiniEditor/Pack//STD_MP//NewSubParcel[position()=$FormPos]">
              <xsl:for-each
                select="Entity_Spatial/Spatial_Element[$Spatial_ElementPos]/Spelement_Unit[$UnitPos]">
                <xsl:choose>
                  <xsl:when test="$ParamCode='Point_Pref'">
                    <xsl:value-of select="Ordinate/@Point_Pref"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Num_Geopoint'">
                    <xsl:value-of select="Ordinate/@Num_Geopoint"/>
                    <xsl:value-of select="$ContourAdd"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='X'">
                    <xsl:value-of select="Ordinate/@X"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Y'">
                    <xsl:value-of select="Ordinate/@Y"/>
                  </xsl:when>
                  <xsl:when test="$ParamCode='Delta_Geopoint'">
                    <xsl:value-of select="Ordinate/@Delta_Geopoint"/>
                  </xsl:when>
                </xsl:choose>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$PageCode='Areas' and $PartCode='Area' and $VersionMPFrom='01'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//Parcel/SubParcels/SubParcel[position()=$FormPos]/Areas/Area">
              <xsl:choose>
                <xsl:when test="$ParamCode='Area'">
                  <xsl:value-of select="Area"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Innccuracy'">
                  <xsl:value-of select="Innccuracy"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
          <xsl:when test="$PageCode='Areas' and $PartCode='Area' and $VersionMPFrom='02'">
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//ExistParcel/SubParcels/SubParcel[position()=$FormPos]/Area">
              <xsl:choose>
                <xsl:when test="$ParamCode='Area'">
                  <xsl:value-of select="Area"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Innccuracy'">
                  <xsl:value-of select="Innccuracy"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
            <xsl:for-each select="/MiniEditor/Pack//STD_MP//NewSubParcel[position()=$FormPos]/Area">
              <xsl:choose>
                <xsl:when test="$ParamCode='Area'">
                  <xsl:value-of select="Area"/>
                </xsl:when>
                <xsl:when test="$ParamCode='Innccuracy'">
                  <xsl:value-of select="Innccuracy"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <!--OLZ-->
      <xsl:when test="($FormCode='OLZ' and $PageCode='Parcels' )">
        <xsl:for-each
          select="(/MiniEditor/Pack//Requests_GZK_Realty//Object/Parcels/Parcel)[position()=$FormPos]">
          <xsl:if test="@exist='yes'">
            <xsl:choose>
              <xsl:when test="$ParamCode='CadastralNumber' and $PartCode='Parcel'">
                <xsl:value-of select="CadastralNumber"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Name'and $PartCode='Parcel'">
                <xsl:value-of select="@Name"/>
              </xsl:when>
              <xsl:when test="$PartCode='ParcelAddress' and $AltCode='000' and $ParamCode='Address'">
                <xsl:value-of select=".//Location/Note"/>
              </xsl:when>
            </xsl:choose>
          </xsl:if>
        </xsl:for-each>
      </xsl:when>
      <xsl:when
        test="$FormCode='OLZ' and $PageCode='SubParcels' and $PartCode='SubParcel' and $ParamCode='Ord_Num'">
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Object/Parcels/Parcel[position()=$FormPos]/SubParcels/SubParcel[$MultiPos]">
          <xsl:value-of select="@Ord_Num"/>
        </xsl:for-each>
      </xsl:when>
      <!--NWZ-->
      <xsl:when test="$FormCode='NWZ' and $PageCode='Parcels'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]">
          <xsl:choose>
            <xsl:when test="$PartCode='Parcel' and $ParamCode='Designation'">
              <xsl:value-of select="@Definition"/>
            </xsl:when>
            <xsl:when test="$PartCode='Parcel' and $ParamCode='Name'">
              <xsl:value-of select="@Name"/>
            </xsl:when>
            <xsl:when test="$PartCode='ParcelAddress' and $AltCode='000' and $ParamCode='Address'">
              <xsl:choose>
                <xsl:when test="$VersionMPFrom='01'">
                  <xsl:value-of select="Location/Address/Note"/>
                </xsl:when>
                <xsl:when test="$VersionMPFrom='02'">
                  <xsl:value-of select="Location/Note"/>
                </xsl:when>
              </xsl:choose>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$FormCode='NWZ' and $PageCode='Category'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]">
          <xsl:choose>
            <xsl:when test="$PartCode='Category' and $ParamCode='Category'">
              <xsl:value-of select="Category/@Category"/>
            </xsl:when>
            <xsl:when test="$PartCode='Utilization' and $ParamCode='ByDoc'">
              <xsl:value-of select="Utilization[$MultiPos]/@ByDoc"/>
            </xsl:when>
            <xsl:when test="$PartCode='Utilization' and $ParamCode='Kind'">
              <xsl:value-of select="Utilization[$MultiPos]/@Kind"/>
            </xsl:when>
            <xsl:when
              test="$PartCode='Providing_Pass_CadastralNumbers' and $ParamCode='Providing_Pass_CadastralNumber'">
              <xsl:value-of select="Providing_Pass_CadastralNumbers/CadastralNumber[$MultiPos]"/>
            </xsl:when>
            <xsl:when
              test="$PartCode='Inner_CadastralNumbers' and $ParamCode='Inner_CadastralNumber'">
              <xsl:value-of select="Inner_CadastralNumbers/CadastralNumber[$MultiPos]"/>
            </xsl:when>
            <xsl:when test="$PartCode='NaturalObject' and $ParamCode='ForestUse'">
              <xsl:value-of select="NaturalObject/ForestUse"/>
            </xsl:when>
            <xsl:when test="$PartCode='NaturalObject' and $ParamCode='Type_ProtectiveForest'">
              <xsl:value-of select="NaturalObject/Type_ProtectiveForest"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Name'">
              <xsl:value-of select="Encumbrances/Encumbrance[$MultiPos]/Name"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Type'">
              <xsl:value-of select="Encumbrances/Encumbrance[$MultiPos]/Type"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$FormCode='NWZ' and $PageCode='Entity_Spatial' and $PartCode='Point'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]">
          <xsl:for-each
            select="
                            (Contours/Contour[$ContourPos]/Entity_Spatial/Spatial_Element[$Spatial_ElementPos]/Spelement_Unit[$UnitPos] |
                            Entity_Spatial/Spatial_Element[$Spatial_ElementPos]/Spelement_Unit[$UnitPos])">
            <xsl:choose>
              <xsl:when test="$ParamCode='Point_Pref'">
                <xsl:value-of select="Ordinate/@Point_Pref"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Num_Geopoint'">
                <xsl:value-of select="Ordinate/@Num_Geopoint"/>
                <xsl:value-of select="$ContourAdd"/>
              </xsl:when>
              <xsl:when test="$ParamCode='X'">
                <xsl:value-of select="Ordinate/@X"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Y'">
                <xsl:value-of select="Ordinate/@Y"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Delta_Geopoint'">
                <xsl:value-of select="Ordinate/@Delta_Geopoint"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Geopoint_Zacrep'">
                <xsl:value-of select="Ordinate/@Geopoint_Zacrep"/>
              </xsl:when>
            </xsl:choose>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$FormCode='NWZ' and $PageCode='Entity_Spatial' and $PartCode='Edge'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]">
          <xsl:for-each
            select="
                            (Contours/Contour[$ContourPos]/Entity_Spatial/Borders/Border[$UnitPos] |
                            Entity_Spatial/Borders/Border[$UnitPos])">
            <xsl:choose>
              <xsl:when test="$ParamCode='FromTo'">
                <xsl:value-of select="@Point1"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="@Point2"/>
                <xsl:value-of select="$ContourAdd"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Length'">
                <xsl:value-of select="Edge/Length"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Definition'">
                <xsl:value-of select="Edge/Definition"/>
              </xsl:when>
            </xsl:choose>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:when>
      <xsl:when
        test="$FormCode='NWZ' and $PageCode='Entity_Spatial' and $PartCode='Square' and 
                (/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Contours">
        <xsl:for-each
          select="((/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]/Contours/Contour)[$MultiPos]">
          <xsl:choose>
            <xsl:when test="$ParamCode='Contour'">
              <xsl:text>(</xsl:text>
              <xsl:value-of select="$MultiPos"/>
              <xsl:text>)</xsl:text>
            </xsl:when>
            <xsl:when test="$ParamCode='Definition'">
              <xsl:value-of select="@Definition"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Area'">
              <xsl:value-of select=".//Area/Area"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Formula'">
              <xsl:text>S(</xsl:text>
              <xsl:value-of select="$MultiPos"/>
              <xsl:text>)=</xsl:text>
              <xsl:value-of select=".//Area/Area"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$FormCode='NWZ' and $PageCode='Areas' and $PartCode='Area'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos]">
          <xsl:choose>
            <xsl:when test="$ParamCode='Area'">
              <xsl:value-of select=".//Area/Area"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Innccuracy'">
              <xsl:value-of select=".//Area/Innccuracy"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <!--NWZPart-->
      <xsl:when test="$FormCode='NWZPart' and $PageCode='Entity_Spatial' and $PartCode='Point'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos1]/SubParcels/SubParcel[position()=$FormPos]">
          <xsl:for-each
            select="Entity_Spatial/Spatial_Element[$Spatial_ElementPos]/Spelement_Unit[$UnitPos]">
            <xsl:choose>
              <xsl:when test="$ParamCode='Point_Pref'">
                <xsl:value-of select="Ordinate/@Point_Pref"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Num_Geopoint'">
                <xsl:value-of select="Ordinate/@Num_Geopoint"/>
                <xsl:value-of select="$ContourAdd"/>
              </xsl:when>
              <xsl:when test="$ParamCode='X'">
                <xsl:value-of select="Ordinate/@X"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Y'">
                <xsl:value-of select="Ordinate/@Y"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Delta_Geopoint'">
                <xsl:value-of select="Ordinate/@Delta_Geopoint"/>
              </xsl:when>
            </xsl:choose>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$FormCode='NWZPart' and $PageCode='Areas' and $PartCode='Area'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos1]/SubParcels/SubParcel[position()=$FormPos]">
          <xsl:choose>
            <xsl:when test="$ParamCode='Area'">
              <xsl:value-of select=".//Area/Area"/>
            </xsl:when>
            <xsl:when test="$ParamCode='Innccuracy'">
              <xsl:value-of select=".//Area/Innccuracy"/>
            </xsl:when>
          </xsl:choose>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="$FormCode='NWZPart' and $PageCode='SubParcels'">
        <xsl:for-each
          select="(/MiniEditor/Pack//STD_MP//*[local-name()='Parcel' or local-name()='NewParcel'])[position()=$FormPos1]/SubParcels/SubParcel[position()=$FormPos]">
          <xsl:choose>
            <xsl:when test="$PartCode='SubParcel' and $AltCode='New' and $ParamCode='Designation'">
              <xsl:value-of select="substring-after(@Definition,'/')"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Name' and $VersionMPFrom='01'">
              <xsl:value-of select="Encumbrances/Encumbrance[$MultiPos]/Name"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Type' and $VersionMPFrom='01'">
              <xsl:call-template name="Trans">
                <xsl:with-param name="x" select="Encumbrances/Encumbrance[$MultiPos]/Type"/>
                <xsl:with-param name="dict">
                  <xsl:call-template name="TEncumbranches"/>
                </xsl:with-param>
                <xsl:with-param name="in" select="$VersionMPFrom"/>
                <xsl:with-param name="out" select="$VersionMPTo"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Name' and $VersionMPFrom='02'">
              <xsl:value-of select="Encumbrance/Name"/>
            </xsl:when>
            <xsl:when test="$PartCode='Encumbrances' and $ParamCode='Type' and $VersionMPFrom='02'">
              <xsl:call-template name="Trans">
                <xsl:with-param name="x" select="Encumbrance/Type"/>
                <xsl:with-param name="dict">
                  <xsl:call-template name="TEncumbranches"/>
                </xsl:with-param>
                <xsl:with-param name="in" select="$VersionMPFrom"/>
                <xsl:with-param name="out" select="$VersionMPTo"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:when test="$PartCode='SubParcel_Realty' and $ParamCode='SubParcel_Realty'">
              <xsl:value-of select="@SubParcel_Realty"/>
            </xsl:when>
          </xsl:choose>

        </xsl:for-each>
      </xsl:when>
      <!--MDZ-->
      <!--MDZPart-->
      <!--NBZ-->
      <xsl:when test="$FormCode='NBZ' and $PageCode='Parcels'">
        <xsl:choose>
          <xsl:when test="$VersionMPFrom='01'">
            <xsl:for-each
              select="/MiniEditor/Pack//Requests_GZK_Realty//Parcel[@exist='neighbour'][position()=$FormPos]">
              <xsl:choose>
                <xsl:when test="$PartCode='Parcel' and $ParamCode='CadastralNumber'">
                  <xsl:value-of select="CadastralNumber"/>
                </xsl:when>
                <xsl:when test="$PartCode='Parcel' and $ParamCode='Name'">
                  <xsl:value-of select="@Name"/>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each
              select="/MiniEditor/Pack//STD_MP//SpecifyRelatedParcel[position()=$FormPos]">
              <xsl:variable name="CadNum">
                <xsl:value-of select="@CadastralNumber"/>
              </xsl:variable>
              <xsl:choose>
                <xsl:when test="$PartCode='Parcel' and $ParamCode='CadastralNumber'">
                  <xsl:value-of select="$CadNum"/>
                </xsl:when>
                <xsl:when test="$PartCode='Parcel' and $ParamCode='Name'">
                  <xsl:for-each
                    select="/MiniEditor/Pack//Requests_GZK_Realty//Parcel[@exist='neighbour']">
                    <xsl:if test="CadastralNumber=$CadNum">
                      <xsl:value-of select="@Name"/>
                    </xsl:if>
                  </xsl:for-each>
                </xsl:when>
              </xsl:choose>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:when test="$FormCode='NBZ' and $PageCode='Entity_Spatial' and $PartCode='Point'">
        <xsl:for-each select="/MiniEditor/Pack//STD_MP//SpecifyRelatedParcel[position()=$FormPos]">
          <xsl:for-each select="ChangeBorder[$MultiPos]">
            <xsl:choose>
              <xsl:when test="$ParamCode='X0'">
                <xsl:value-of select="OldOrdinate/@X"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Y0'">
                <xsl:value-of select="OldOrdinate/@Y"/>
              </xsl:when>
              <xsl:when test="$ParamCode='X'">
                <xsl:value-of select="NewOrdinate/@X"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Y'">
                <xsl:value-of select="NewOrdinate/@Y"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Point_Pref'">
                <xsl:value-of select="NewOrdinate/@Point_Pref"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Num_Geopoint'">
                <xsl:value-of select="NewOrdinate/@Num_Geopoint"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Delta_Geopoint'">
                <xsl:value-of select="NewOrdinate/@Delta_Geopoint"/>
              </xsl:when>
              <xsl:when test="$ParamCode='Geopoint_Zacrep'">
                <xsl:value-of select="NewOrdinate/@Geopoint_Zacrep"/>
              </xsl:when>
            </xsl:choose>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="node()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Параметры ParamSelectList: вычисление значения @id выбранного значения Item (надо менять - для всех ParamSelectList) -->
  <xsl:template name="ParamSelectListId">
    <xsl:param name="FormCode"/>
    <xsl:param name="FormCode1"/>
    <xsl:param name="FormPos"/>
    <xsl:param name="FormPos1"/>
    <xsl:param name="PageCode"/>
    <xsl:param name="PartCode"/>
    <xsl:param name="AltCode"/>
    <xsl:param name="MultiPos"/>
    <xsl:param name="ParamCode"/>
    <xsl:param name="ListName"/>
    <xsl:variable name="ThisListItem">
      <xsl:choose>
        <!-- Вариант Any -->
        <xsl:when test="$Variant='Any'">
          <xsl:for-each
            select="(
                      //Pack[$FormPos1=0]//Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/ParamList[@Code=$ParamCode]
                      | //Pack[$FormPos1!=0]//Form[@Code=$FormCode1][position()=$FormPos1]/Form[@Code=$FormCode][position()=$FormPos]/Page[@Code=$PageCode]/Sections[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][position()=$MultiPos]/ParamList[@Code=$ParamCode]
                      )">
            <xsl:call-template name="ThisListItem">
              <xsl:with-param name="ListName" select="$ListName"/>
            </xsl:call-template>
          </xsl:for-each>
        </xsl:when>
        <!-- Вариант MiniEditorExist -->
        <xsl:when test="$MiniEditorExist='true'">
          <xsl:for-each
            select="
                      /MiniEditor/Pack/File/Content/MiniEditor/Forms/
                      Form[@Code=$FormCode and @Selected='true' and (@ParentID='' or 
                      @ParentID=concat($FormCode1,concat('_',/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Code=$FormCode1 and (not(@SetNumber) or @SetNumber=$FormPos1)]/@ID)))
                      ][position()=$FormPos]
                      /Page[@Code=$PageCode]/*[@Code=$PartCode]/Section[not(@Code) or @Code=$AltCode][$MultiPos]/*[@Code=$ParamCode]
                      ">
            <xsl:variable name="id" select="Item/@id"/>
            <xsl:for-each
              select="/MiniEditor/Pack/File/Content/MiniEditor/Lists/List[@Name=$ListName]/Items/Item[@id=$id]">
              <xsl:call-template name="ThisListItem">
                <xsl:with-param name="ListName" select="$ListName"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <!-- Вариант ГКН -->
        <xsl:when test="/MiniEditor/Pack[//Requests_GZK_Realty]">
          <!-- Конкретный список -->
          <xsl:choose>
            <xsl:when
              test="$FormCode='Request' and $PartCode='Delivery' and $AltCode='OKU' and $ParamCode='Name_OKU' and count(/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_RR)>0">
              <xsl:for-each
                select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_RR">
                <xsl:call-template name="ThisListItem">
                  <xsl:with-param name="ListName" select="$ListName"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
            <xsl:when
              test="$FormCode='Request' and $PartCode='Delivery' and $AltCode='OKU' and $ParamCode='Name_OKU' and count(/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_OKU_BTI)>0">
              <xsl:for-each
                select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_OKU_BTI">
                <xsl:call-template name="ThisListItem">
                  <xsl:with-param name="ListName" select="$ListName"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
          </xsl:choose>
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="ListIntegrate" select="concat($ListOld,$ListNew)"/>
    <xsl:variable name="ListId"
      select="substring-before(substring-after($ListIntegrate,$ThisListItem),$ListSeparator)"/>
    <xsl:value-of select="$ListId"/>
  </xsl:template>

  <!-- Списки Lists: сохранение всех Item из Pack в виде строки ListNew (надо менять -  для всех List) -->
  <xsl:variable name="ListNew">
    <xsl:choose>
      <!-- Вариант Any -->
      <xsl:when test="$Variant='Any'">
        <xsl:for-each select="/MiniEditor/Lists/List">
          <xsl:variable name="ListName" select="@Name"/>
          <xsl:for-each select="//Pack//Form/Page/Sections/Section/ParamList[@ListName=$ListName]">
            <xsl:call-template name="ThisListItem">
              <xsl:with-param name="ListName" select="@ListName"/>
            </xsl:call-template>
            <xsl:value-of select="position()"/>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:when>
      <!-- Вариант MiniEditorExist -->
      <xsl:when test="$MiniEditorExist='true'">
        <xsl:for-each select="/MiniEditor/Lists/List">
          <xsl:variable name="ListName" select="@Name"/>
          <xsl:for-each
            select="/MiniEditor/Pack//MiniEditor/Forms/Form[@Selected='true']/Page/*[@Selected='true']/Section[not(@Selected='false')]/ParamSelectList[@ListName=$ListName and Item]">
            <xsl:variable name="id" select="Item/@id"/>
            <xsl:for-each select="../../../../../../Lists/List[@Name=$ListName]/Items/Item[@id=$id]">
              <xsl:call-template name="ThisListItem">
                <xsl:with-param name="ListName" select="$ListName"/>
              </xsl:call-template>
            </xsl:for-each>
            <xsl:value-of select="position()"/>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:when>
      <!-- Вариант ГКН -->
      <xsl:when test="/MiniEditor/Pack[//Requests_GZK_Realty]">
        <!-- Конкретный список -->
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_RR">
          <xsl:call-template name="ThisListItem">
            <xsl:with-param name="ListName" select="'OKU'"/>
          </xsl:call-template>
          <xsl:value-of select="position()"/>
        </xsl:for-each>
        <xsl:for-each
          select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_OKU_BTI">
          <xsl:call-template name="ThisListItem">
            <xsl:with-param name="ListName" select="'OKU'"/>
          </xsl:call-template>
          <xsl:value-of select="position()"/>
        </xsl:for-each>
      </xsl:when>
    </xsl:choose>
    <xsl:value-of select="$ListSeparator"/>
  </xsl:variable>

  <!-- Списки Lists: порождение раздела Items для одного List (надо менять -  для всех List) -->
  <xsl:template name="Items">
    <xsl:param name="ListName"/>
    <xsl:copy>
      <!-- Копирование существующих Item -->
      <xsl:apply-templates select="@* | node()"/>
      <!-- Добавление новых Item из //Pack -->
      <xsl:choose>
        <!-- Вариант Any -->
        <xsl:when test="$Variant='Any'">
          <xsl:for-each select="//Pack//Form/Page/Sections/Section/ParamList[@ListName=$ListName]">
            <xsl:call-template name="Item">
              <xsl:with-param name="ListName" select="$ListName"/>
              <xsl:with-param name="ListPos" select="position()"/>
            </xsl:call-template>
          </xsl:for-each>
        </xsl:when>
        <!-- Вариант MiniEditorExist -->
        <xsl:when test="$MiniEditorExist='true'">
          <xsl:for-each
            select="/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Selected='true']/Page/*[@Selected='true']/Section[not(@Selected='false')]/ParamSelectList[@ListName=$ListName and Item]">
            <xsl:variable name="id" select="Item/@id"/>
            <xsl:variable name="pos" select="position()"/>
            <xsl:for-each
              select="/MiniEditor/Pack/File/Content/MiniEditor/Lists/List[@Name=$ListName]/Items/Item[@id=$id]">
              <xsl:call-template name="Item">
                <xsl:with-param name="ListName" select="$ListName"/>
                <xsl:with-param name="ListPos" select="$pos"/>
              </xsl:call-template>
            </xsl:for-each>

          </xsl:for-each>
        </xsl:when>
        <!-- Вариант ГКН -->
        <xsl:when test="/MiniEditor/Pack[//Requests_GZK_Realty]">
          <!-- Конкретный список -->
          <xsl:choose>
            <xsl:when test="$ListName='OKU'">
              <xsl:for-each
                select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_RR">
                <xsl:call-template name="Item">
                  <xsl:with-param name="ListName" select="$ListName"/>
                  <xsl:with-param name="ListPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
              <xsl:for-each
                select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_OKU_BTI">
                <xsl:call-template name="Item">
                  <xsl:with-param name="ListName" select="$ListName"/>
                  <xsl:with-param name="ListPos" select="position()"/>
                </xsl:call-template>
              </xsl:for-each>
            </xsl:when>
          </xsl:choose>
        </xsl:when>
      </xsl:choose>
    </xsl:copy>
  </xsl:template>

  <!-- Списки Lists: порождение одного Item в разделе Items (надо менять - для всех List) -->
  <xsl:template name="Item">
    <xsl:param name="ListName"/>
    <xsl:param name="ListPos"/>
    <xsl:variable name="ThisListItem">
      <xsl:call-template name="ThisListItem">
        <xsl:with-param name="ListName" select="$ListName"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="ListId"
      select="substring-before(substring-after($ListNew,$ThisListItem),$ListSeparator)"/>
    <xsl:choose>
      <!-- Если <ThisListItem> встречается в <ListOld> - Item не добавляем -->
      <xsl:when test="contains($ListOld,$ThisListItem)"/>
      <!-- Если <ThisListItem> встречается в <ListNew> повторно - Item не добавляем -->
      <xsl:when test="$ListId!=$ListPos"/>
      <!-- Иначе Item добавляем -->
      <xsl:otherwise>
        <Item>
          <xsl:attribute name="id">
            <xsl:value-of select="$ListId"/>
          </xsl:attribute>
          <xsl:for-each select="/MiniEditor/Lists/List[@Name=$ListName]/Fields/Param">
            <xsl:variable name="ListFieldsPos" select="position()"/>
            <xsl:variable name="ListFieldsCode" select="@Code"/>
            <xsl:copy>
              <xsl:apply-templates select="@*"/>
              <xsl:choose>
                <!-- Вариант Any -->
                <xsl:when test="$Variant='Any'">
                  <xsl:for-each
                    select="(//Pack//Form/Page/Sections/Section/ParamList[@ListName=$ListName])[$ListPos]">
                    <!-- Случай, когда в Pack элементы списка упорядочены так же, как в Fields -->
                    <xsl:for-each select="*[$ListFieldsPos]">
                      <xsl:value-of select="."/>
                    </xsl:for-each>
                  </xsl:for-each>
                </xsl:when>
                <!-- Вариант MiniEditorExist -->
                <xsl:when test="$MiniEditorExist='true'">
                  <xsl:for-each
                    select="(/MiniEditor/Pack/File/Content/MiniEditor/Forms/Form[@Selected='true']/Page/*[@Selected='true']/Section[not(@Selected='false')]/ParamSelectList[@ListName=$ListName and Item])[$ListPos]">
                    <xsl:variable name="id" select="Item/@id"/>
                    <xsl:for-each
                      select="/MiniEditor/Pack/File/Content/MiniEditor/Lists/List[@Name=$ListName]/Items/Item[@id=$id]">
                      <xsl:for-each select="*[$ListFieldsPos]">
                        <xsl:value-of select="."/>
                      </xsl:for-each>
                    </xsl:for-each>
                  </xsl:for-each>
                </xsl:when>
                <!-- Вариант ГКН -->
                <xsl:when test="/MiniEditor/Pack[//Requests_GZK_Realty]">
                  <!-- Конкретный список в позиции $ListPos -->
                  <xsl:choose>
                    <xsl:when test="$ListName='OKU'">
                      <xsl:for-each
                        select="(/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_RR)[$ListPos]">
                        <!-- Случай, когда в Pack элементы списка упорядочены так же, как в Fields -->
                        <xsl:for-each select="*[$ListFieldsPos]">
                          <xsl:value-of select="."/>
                        </xsl:for-each>
                      </xsl:for-each>
                      <xsl:for-each
                        select="(/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Delivery/Organization_OKU_BTI)[$ListPos]">
                        <!-- Случай, когда в Pack элементы списка упорядочены так же, как в Fields -->
                        <xsl:for-each select="*[$ListFieldsPos]">
                          <xsl:value-of select="."/>
                        </xsl:for-each>
                      </xsl:for-each>
                    </xsl:when>
                  </xsl:choose>
                </xsl:when>
              </xsl:choose>
            </xsl:copy>
          </xsl:for-each>
        </Item>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Сравнение данных физических лиц -->
  <xsl:template name="CompareF">
    <xsl:variable name="testPerson">
      <xsl:for-each
        select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Person">
        <xsl:choose>
          <xsl:when test="FIO/Surname!='' and $FIO1!=FIO/Surname">false</xsl:when>
          <xsl:when test="FIO/First!='' and $FIO2!=FIO/First">false</xsl:when>
        </xsl:choose>
      </xsl:for-each>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$testPerson=''">true</xsl:when>
      <xsl:otherwise>false</xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- Сравнение данных юридических лиц -->
  <xsl:template name="CompareJ">
    <xsl:variable name="testOrganization">
      <xsl:for-each
        select="/MiniEditor/Pack//Requests_GZK_Realty//Declarants/Declarant/Organization">
        <xsl:choose>
          <xsl:when test="Name!='' and Name!=$Organization">false</xsl:when>
          <xsl:when test="INN!='' and INN!=$INNJ">false</xsl:when>
          <xsl:when test="Code_CPP!='' and Code_CPP!=$KPP">false</xsl:when>
          <xsl:when test="E-mail!='' and $Email!=E-mail">false</xsl:when>
        </xsl:choose>
      </xsl:for-each>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$testOrganization=''">true</xsl:when>
      <xsl:otherwise>false</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
